diff --git a/packages/survey-core/src/helpers.ts b/packages/survey-core/src/helpers.ts index 14513b6fb4..7d2649af24 100644 --- a/packages/survey-core/src/helpers.ts +++ b/packages/survey-core/src/helpers.ts @@ -215,11 +215,13 @@ export class Helpers { } private static getNumberCore(value: any): number { if (typeof value == "string") { - if(!value.trim()) return NaN; + value = value.trim(); + if(!value) return NaN; if(value.indexOf("0x") == 0) { if(value.length > 32) return NaN; return parseInt(value); } + if(value.length > 15 && Helpers.isDigitsOnly(value)) return NaN; if(Helpers.isStringHasOperator(value)) return NaN; } value = this.prepareStringToNumber(value); @@ -320,6 +322,13 @@ export class Helpers { public static isCharDigit(ch: string): boolean { return ch >= "0" && ch <= "9"; } + public static isDigitsOnly(str: string): boolean { + if(!str) return false; + for(let i = 0; i < str.length; i ++) { + if(!Helpers.isCharDigit(str[i])) return false; + } + return true; + } private static getNumberFromStr(str: string, index: number): number { if(!this.isCharDigit(str[index])) return NaN; let nStr = ""; diff --git a/packages/survey-core/tests/expressions/expressionParserTest.ts b/packages/survey-core/tests/expressions/expressionParserTest.ts index 3083fe319d..98a743cb4f 100644 --- a/packages/survey-core/tests/expressions/expressionParserTest.ts +++ b/packages/survey-core/tests/expressions/expressionParserTest.ts @@ -1683,3 +1683,10 @@ QUnit.test("ExpressionRunner: apply custom converter, #8634", function(assert) { settings.parseNumber = oldCallback; }); +QUnit.test("ExpressionRunner: do not convert to number extreme large strings", function(assert) { + const runner = new ExpressionRunner("{a} + 2"); + const values: any = { a: "999999999999999" }; + assert.strictEqual(runner.run(values), 1000000000000001, "it is a number"); + values.a = "9999999999999999"; + assert.strictEqual(runner.run(values), "99999999999999992", "it is a string"); +});