Skip to content

Commit 3554e61

Browse files
authored
Don't validate formula parameter value (baserow#4207)
1 parent fffdb8d commit 3554e61

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

web-frontend/modules/core/formula/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export const isFormulaValid = (formula, functions) => {
4141

4242
try {
4343
const tree = parseBaserowFormula(formula)
44-
new JavascriptExecutor(functions).visit(tree)
44+
// we don't validate type as we can't without the right context
45+
new JavascriptExecutor(functions, {}, false).visit(tree)
4546
return true
4647
} catch (err) {
4748
return false

web-frontend/modules/core/formula/parser/javascriptExecutor.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ export class FunctionCollection {
1212
}
1313

1414
export default class JavascriptExecutor extends BaserowFormulaVisitor {
15-
constructor(functions, context = {}) {
15+
constructor(functions, context = {}, validateArgsType = true) {
1616
super()
1717
this.functions = functions
1818
this.context = context
19+
this.validateArgsType = validateArgsType
1920
}
2021

2122
visitRoot(ctx) {
@@ -65,7 +66,7 @@ export default class JavascriptExecutor extends BaserowFormulaVisitor {
6566

6667
const formulaFunctionType = this.functions.get(functionName)
6768

68-
formulaFunctionType.validateArgs(args)
69+
formulaFunctionType.validateArgs(args, this.validateArgsType)
6970

7071
const argsParsed = formulaFunctionType.parseArgs(args)
7172

web-frontend/modules/core/runtimeFormulaTypes.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,15 @@ export class RuntimeFormulaFunction extends Registerable {
7171
* @throws InvalidNumberOfArguments - If the number of arguments is incorrect
7272
* @throws InvalidFormulaArgumentType - If any of the arguments have a wrong type
7373
*/
74-
validateArgs(args) {
74+
validateArgs(args, validateType = true) {
7575
if (!this.validateNumberOfArgs(args)) {
7676
throw new InvalidNumberOfArguments(this, args)
7777
}
78-
const invalidArg = this.validateTypeOfArgs(args)
79-
if (invalidArg) {
80-
throw new InvalidFormulaArgumentType(this, invalidArg)
78+
if (validateType) {
79+
const invalidArg = this.validateTypeOfArgs(args)
80+
if (invalidArg) {
81+
throw new InvalidFormulaArgumentType(this, invalidArg)
82+
}
8183
}
8284
}
8385

web-frontend/modules/core/utils/validator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export const ensureNonEmptyString = (value, options) => {
185185
* @param {boolean} useStrict - Whether to be strict in how the value is interpreted.
186186
* @returns {boolean} The value as a boolean.
187187
*/
188-
export const ensureBoolean = (value, { useStrict = true }) => {
188+
export const ensureBoolean = (value, { useStrict = true } = {}) => {
189189
if (trueValues.includes(value)) {
190190
return true
191191
} else if (falseValues.includes(value)) {

0 commit comments

Comments
 (0)