fix infinite loop

This commit is contained in:
gaollard 2021-05-16 14:08:26 +08:00
parent d8d4013045
commit 2b5472d1ca

View File

@ -461,7 +461,7 @@ function tokenizer(input) {
// Then we're going to loop through each character in the sequence until // Then we're going to loop through each character in the sequence until
// we encounter a character that is not a number, pushing each character // we encounter a character that is not a number, pushing each character
// that is a number to our `value` and incrementing `current` as we go. // that is a number to our `value` and incrementing `current` as we go.
while (NUMBERS.test(char)) { while (current < input.length && NUMBERS.test(char)) {
value += char; value += char;
char = input[++current]; char = input[++current];
} }
@ -484,6 +484,9 @@ function tokenizer(input) {
// Keep a `value` variable for building up our string token. // Keep a `value` variable for building up our string token.
let value = ''; let value = '';
// Check closed double quote
if (current < input.length - 1) {
// We'll skip the opening double quote in our token. // We'll skip the opening double quote in our token.
char = input[++current]; char = input[++current];
@ -494,8 +497,16 @@ function tokenizer(input) {
char = input[++current]; char = input[++current];
} }
// Check closed double quote
if (char !== '"') {
throw new Error('invalid string with no closed "');
}
// Skip the closing double quote. // Skip the closing double quote.
char = input[++current]; char = input[++current];
} else {
throw new Error('invalid string with no closed "');
}
// And add our `string` token to the `tokens` array. // And add our `string` token to the `tokens` array.
tokens.push({ type: 'string', value }); tokens.push({ type: 'string', value });
@ -517,7 +528,7 @@ function tokenizer(input) {
// Again we're just going to loop through all the letters pushing them to // Again we're just going to loop through all the letters pushing them to
// a value. // a value.
while (LETTERS.test(char)) { while (current < input.length && LETTERS.test(char)) {
value += char; value += char;
char = input[++current]; char = input[++current];
} }