Skip to content

Commit

Permalink
Avoid infinite loop if errors.unterminated does not throw
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jul 19, 2022
1 parent a98c722 commit f879f44
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/babel-helper-string-parser/src/index.ts
Expand Up @@ -65,11 +65,12 @@ export function readStringContents(
for (;;) {
if (pos >= length) {
errors.unterminated(initialPos, initialLineStart, initialCurLine);
break;
}
const ch = input.charCodeAt(pos);
if (isStringEnd(type, ch, input, pos)) {
out += input.slice(chunkStart, pos);
return { pos, str: out, containsInvalid, lineStart, curLine };
break;
}
if (ch === charCodes.backslash) {
out += input.slice(chunkStart, pos);
Expand Down Expand Up @@ -119,6 +120,7 @@ export function readStringContents(
++pos;
}
}
return { pos, str: out, containsInvalid, lineStart, curLine };
}

function isStringEnd(
Expand Down

0 comments on commit f879f44

Please sign in to comment.