Add check and testcases for invalid binary digits and octal digits
This commit is contained in:
parent
123b2ebda7
commit
77b8f461a3
1 changed files with 8 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue