From 77b8f461a3dd55ea9241f01d46a5808c7aa2c39a Mon Sep 17 00:00:00 2001 From: Yui T Date: Sat, 29 Nov 2014 16:46:01 -0800 Subject: [PATCH] Add check and testcases for invalid binary digits and octal digits --- src/compiler/scanner.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index b55fd53e0cc..45723de983d 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -757,6 +757,9 @@ module ts { Debug.assert(base !== 2 || base !== 8, "Expected either base 2 or base 8"); var value = 0; + // For counting number of digits; Valid binaryIntegerLiteral must have at least one binary digit following B or b. + // Similarly valid octalIntegerLiteral must have at least one octal digit following o or O. + var numberOfDigits = 0; while (true) { var ch = text.charCodeAt(pos); var valueOfCh = ch - CharacterCodes._0; @@ -765,6 +768,11 @@ module ts { } value = value * base + valueOfCh; pos++; + numberOfDigits++; + } + // Invalid binaryIntegerLiteral or octalIntegerLiteral + if (numberOfDigits === 0) { + return -1; } return value; }