Skip to content

Commit

Permalink
Sanitize file changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaiola committed Oct 13, 2023
1 parent 99c4ada commit 84a6058
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 253 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.DS_Store
/nbproject/private/
/node_modules
.brackets.json
Expand All @@ -8,4 +7,4 @@ build
/bower_components
/tmp
/yarn-error.log
**/reports
/reports/
4 changes: 2 additions & 2 deletions src/calc2/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ export class Main extends React.Component<Props, State> {
<Route path="/relax/landing" component={Landing} />
<Route path="/relax/help" component={Help} />
<Route path="/relax/imprint" component={Imprint} />
<Redirect from="/relax/calc" to="/relax/calc/local/ufes/local/0" exact strict />
<Redirect from="/relax/calc" to="/relax/calc/local/uibk/local/0" exact strict />
<Route path="/relax/calc/:source/:id/:filename/:index" component={ConnectedCalc} />
<Route path="/relax/calc/:source/:id" component={ConnectedCalc} />
<Route path="/relax/api/:source/:id/:filename/:index" component={ConnectedCalc} />
<Route path="/relax/calc/:source/:id/:filename/:index" component={ConnectedCalc} />
<Route path="/relax/api/:source/:id" component={ConnectedCalc} />
<Route render={match => (
<div className="view-min"><h1>404</h1>
Expand Down
43 changes: 10 additions & 33 deletions src/calc2/store/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,39 +68,16 @@ export function* rootSaga() {
};
yield saga.put(success);
if (setCurrent !== undefined && loadedGroups.length > 0) {
// In case the :filename and :index are set in the URL,
// it's necessary to set the correct group accordingly
if (setCurrent && setCurrent != 'first' &&
setCurrent.filename && setCurrent.index) {
for(var i=0;i<loadedGroups.length;i++) {
const g = loadedGroups[i];
const { source, id, filename, index } = g.groupInfo;
if (filename == setCurrent.filename && index == setCurrent.index) {
const setCurrent: GROUP_SET_CURRENT = {
type: 'GROUP_SET_CURRENT',
source,
id,
filename,
index,
};
yield saga.put(setCurrent);
break;
}
}
}
// Otherwise, just try using the first group
else {
const { source, id, filename } = loadedGroups[0].groupInfo;

const setCurrent: GROUP_SET_CURRENT = {
type: 'GROUP_SET_CURRENT',
source,
id,
filename,
index: 0,
};
yield saga.put(setCurrent);
}
const { source, id, filename } = loadedGroups[0].groupInfo;

const setCurrent: GROUP_SET_CURRENT = {
type: 'GROUP_SET_CURRENT',
source,
id,
filename,
index: 0,
};
yield saga.put(setCurrent);
}
}
catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion src/calc2/utils/groupUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export function loadGroupsFromSource(source: GroupSourceType, id: string, mainta
reject(new Error('gist ' + id + ' not found'));
},
},
async: false,
async: true,
});
break;
}
Expand Down
7 changes: 1 addition & 6 deletions src/calc2/views/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ export class Api extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {};
// Fix issue of parsing + as a space
// https://www.npmjs.com/package/query-string
// https://github.com/sindresorhus/query-string/issues/305
// https://stackoverflow.com/questions/2678551/when-to-encode-space-to-plus-or-20
// https://stackoverflow.com/questions/3794919/replace-all-spaces-in-a-string-with
this.query = atob(props.params.query.split(' ').join('+'))
this.query = atob(props.params.query)
}

componentDidMount() {
Expand Down
5 changes: 0 additions & 5 deletions src/calc2/views/calc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ export class Calc extends React.Component<Props> {
})*/
this.apiView = this.props.location.pathname.split("/")[2] == "api"
this.params = queryString.parse(this.props.location.search)

// It's necessary to load remote group synchronouly
if (this.apiView) {
this.loadGroup(this.props);
}
}

componentDidUpdate(prevProps: Props): void {
Expand Down
39 changes: 3 additions & 36 deletions src/calc2/views/help.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1942,18 +1942,6 @@ export class Help extends React.Component<Props> {
<br />This is not in the SQL standard but is a PostgreSQL extension.
</td>
</tr>
<tr>
<td><code>a:string REGEXP 'PATTERN'<br />
a:string RLIKE 'PATTERN'</code></td>
<td>boolean</td>
<td>returns true if expression evaluating to a string <code>a</code> matches
the pattern given as the second operand, false otherwise.
<br />
The pattern has to be given as a string literal and it can be an extended regular expression, the syntax for
which is discussed in <a href="https://dev.mysql.com/doc/refman/8.0/en/regexp.html#regexp-syntax">Regular Expression Syntax</a>.
<br />This might not be in the SQL standard but is supported in MySQL.
</td>
</tr>
<tr>
<td>
<code>a + b
Expand Down Expand Up @@ -2052,12 +2040,9 @@ export class Help extends React.Component<Props> {
</tr>

<tr>
<td><code>concat(a:"any" [, ...])</code></td>
<td><code>concat(a:string [, ...])</code></td>
<td>string</td>
<td>returns the string that results from concatenating the arguments.
<br />May have one or more arguments. A non-string argument is implicitly converted to its equivalent string form and then concatenated. Returns null if any argument is null (like in <a
href="https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_concat">MySQL</a>).
</td>
<td>concatenates the given strings</td>
</tr>
<tr>
<td><code>upper(a:string)
Expand All @@ -2072,24 +2057,6 @@ export class Help extends React.Component<Props> {
<td>converts the given string to lower-case</td>
</tr>

<tr>
<td><code>repeat(str:string, count:number)</code></td>
<td>string</td>
<td>returns a string consisting of the string str repeated count times. If count is less than 1, returns an empty string. Returns null if str or count are null.</td>
</tr>

<tr>
<td><code>replace(str:string, from_str:string, to_str:string)</code></td>
<td>string</td>
<td>returns the string str with all occurrences of the string from_str replaced by the string to_str. replace() performs a case-sensitive match when searching for from_str.</td>
</tr>

<tr>
<td><code>reverse(a:string)</code></td>
<td>string</td>
<td>returns the given string with the order of the characters reversed.</td>
</tr>

<tr>
<td><code>strlen(a:string)</code></td>
<td>number</td>
Expand Down Expand Up @@ -2185,7 +2152,7 @@ export class Help extends React.Component<Props> {
</tr>
<tr>
<td>5</td>
<td>= (comparison), {'>'}=, {'>'}, {'<'}=, {'<'}, {'<'}{'>'}, !=, LIKE, ILIKE, REGEXP, RLIKE</td>
<td>= (comparison), {'>'}=, {'>'}, {'<'}=, {'<'}, {'<'}{'>'}, !=, LIKE, ILIKE</td>
</tr>
<tr>
<td>6</td>
Expand Down
73 changes: 3 additions & 70 deletions src/db/exec/ValueExpr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,6 @@ export class ValueExprGeneric extends ValueExpr {
return ValueExprGeneric._condition_compare(a, b, typeA, this._func);
case 'like':
case 'ilike':
case 'regexp':
case 'rlike':
if(!this._regex){
throw new Error(`regex should have been set by check`);
}
Expand Down Expand Up @@ -598,18 +596,6 @@ export class ValueExprGeneric extends ValueExpr {

this._regex = new RegExp('^' + regex_str + '$', flags);

break;
case 'regexp':
case 'rlike':
this._args[0].check(schemaA, schemaB);
if (this._args[1].getDataType() !== 'string' || this._args[1]._func !== 'constant') {
return false;
}

// cache regex
const txt = this._args[1]._args[0]; // direct access of constant value
let regex_txt = txt;
this._regex = new RegExp(regex_txt);
break;
default:
throw new Error('this should not happen!');
Expand Down Expand Up @@ -644,30 +630,6 @@ export class ValueExprGeneric extends ValueExpr {
value += a;
}
return value;
case 'repeat':
const rep = this._args[0].evaluate(tupleA, tupleB, row, statementSession);
const count = this._args[1].evaluate(tupleA, tupleB, row, statementSession);

if (rep === null || count === null) {
return null;
}
else {
return rep.repeat(count >= 0 ? count : 0);
}
case 'replace':
const str = this._args[0].evaluate(tupleA, tupleB, row, statementSession);
const from_str = this._args[1].evaluate(tupleA, tupleB, row, statementSession);
const to_str = this._args[2].evaluate(tupleA, tupleB, row, statementSession);
return str.replace(new RegExp(from_str, 'g'), to_str);
case 'reverse':
const r = this._args[0].evaluate(tupleA, tupleB, row, statementSession);

if (r === null) {
return null;
}
else {
return r.split('').reverse().join('');
}
default:
throw new Error('this should not happen!');
}
Expand Down Expand Up @@ -904,32 +866,7 @@ export class ValueExprGeneric extends ValueExpr {
return true;
case 'lower':
case 'upper':
case 'reverse':
return this._checkArgsDataType(schemaA, schemaB, ['string']);
case 'replace':
return this._checkArgsDataType(schemaA, schemaB, ['string', 'string', 'string']);
case 'repeat':
//return this._checkArgsDataType(schemaA, schemaB, ['string', 'number']);

if (this._args.length !== 2) {
throw new Error('this should not happen!');
}

// arguments must be of type string and number, or null
this._args[0].check(schemaA, schemaB);
const typeStr = this._args[0].getDataType();
this._args[1].check(schemaA, schemaB);
const typeCount = this._args[1].getDataType();

if ( (typeStr !== 'string' && typeStr !== 'null') ||
(typeCount !== 'number' && typeCount !== 'null') ) {
this.throwExecutionError(i18n.t('db.messages.exec.error-function-expects-type', {
func: 'repeat()',
expected: ['string', 'number'],
given: [typeStr, typeCount],
}));
}
break;
case 'concat':
if (this._args.length === 0) {
throw new Error('this should not happen!');
Expand All @@ -946,9 +883,9 @@ export class ValueExprGeneric extends ValueExpr {
if (this._dataType === 'null' && dataType !== 'null') {
this._dataTypeCalculated = dataType;
}
// else if (dataType !== 'null' && this._dataType !== dataType) {
// this.throwExecutionError(i18n.t('db.messages.exec.error-function-expects-arguments-of-same-type', {func: 'CONCAT()'}));
// }
else if (dataType !== 'null' && this._dataType !== dataType) {
this.throwExecutionError(i18n.t('db.messages.exec.error-function-expects-arguments-of-same-type', {func: 'CONCAT()'}));
}
}
break;
default:
Expand Down Expand Up @@ -1064,8 +1001,6 @@ export class ValueExprGeneric extends ValueExpr {
case 'concat':
case 'upper':
case 'lower':
case 'replace':
case 'reverse':
case 'date':
return printFunction.call(this, _func.toUpperCase());
case 'strlen':
Expand Down Expand Up @@ -1097,8 +1032,6 @@ export class ValueExprGeneric extends ValueExpr {
case 'xor':
case 'like':
case 'ilike':
case 'regexp':
case 'rlike':
case '=':
return binary.call(this, _func);

Expand Down
5 changes: 0 additions & 5 deletions src/db/parser/grammar_ra.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,6 @@ declare module relalgAst {
| 'and'
| 'like'
| 'ilike'
| 'regexp'
| 'rlike'
| 'add'
| 'sub'
| 'mul'
Expand All @@ -355,9 +353,6 @@ declare module relalgAst {
| 'subdate'
| 'upper'
| 'lower'
| 'repeat'
| 'replace'
| 'reverse'
| 'strlen'
| 'abs'
| 'floor'
Expand Down
7 changes: 2 additions & 5 deletions src/db/parser/grammar_ra.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ expr_rest_boolean_comparison
codeInfo: getCodeInfo()
};
}
/ _ o:('like'i / 'ilike'i / 'regexp'i / 'rlike'i) _ right:valueExprConstants
/ _ o:('like'i / 'ilike'i) _ right:valueExprConstants
{
if(right.datatype !== 'string'){
error(t('db.messages.parser.error-valueexpr-like-operand-no-string'));
Expand Down Expand Up @@ -1505,7 +1505,6 @@ valueExprFunctionsNary
= func:(
('coalesce'i { return ['coalesce', 'null']; })
/ ('concat'i { return ['concat', 'string']; })
/ ('replace'i { return ['replace', 'string']; })
)
'(' _ arg0:valueExpr _ argn:(',' _ valueExpr _ )* ')'
{
Expand Down Expand Up @@ -1533,7 +1532,6 @@ valueExprFunctionsBinary
/ ('sub'i { return ['sub', 'number']; })
/ ('mul'i { return ['mul', 'number']; })
/ ('div'i { return ['div', 'number']; })
/ ('repeat'i { return ['repeat', 'string']; })
)
'(' _ arg0:valueExpr _ ',' _ arg1:valueExpr _ ')'
{
Expand All @@ -1553,7 +1551,6 @@ valueExprFunctionsUnary
/ ('ucase'i { return ['upper', 'string']; })
/ ('lower'i { return ['lower', 'string']; })
/ ('lcase'i { return ['lower', 'string']; })
/ ('reverse'i { return ['reverse', 'string']; })
/ ('length'i { return ['strlen', 'number']; })
/ ('abs'i { return ['abs', 'number']; })
/ ('floor'i { return ['floor', 'number']; })
Expand Down Expand Up @@ -1708,7 +1705,7 @@ reference: https://dev.mysql.com/doc/refman/5.7/en/operator-precedence.html
2: - (unary minus)
3: *, /, %
4: -, +
5: = (comparison), >=, >, <=, <, <>, !=, IS, LIKE, REGEXP, RLIKE
5: = (comparison), >=, >, <=, <, <>, !=, IS, LIKE
6: CASE, WHEN, THEN, ELSE
7: AND
8: XOR
Expand Down
Loading

0 comments on commit 84a6058

Please sign in to comment.