fix: don't hang on a tag whose expression ends with a trailing slash (#18350)

close https://github.com/sveltejs/svelte/issues/18349
pull/18351/head
Yuichiro Yamashita 3 months ago committed by GitHub
parent c74f44fff9
commit b471c15e61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: prevent infinite loop when a tag's expression ends with a trailing `/` at the end of the input

@ -107,7 +107,11 @@ export function find_matching_bracket(template, index, open) {
continue; continue;
case '/': { case '/': {
const next_char = template[i + 1]; const next_char = template[i + 1];
if (!next_char) continue; if (!next_char) {
// `/` is the last character; advance past it so we don't loop forever
i++;
continue;
}
if (next_char === '/') { if (next_char === '/') {
i = infinity_if_negative(template.indexOf('\n', i + 1)) + '\n'.length; i = infinity_if_negative(template.indexOf('\n', i + 1)) + '\n'.length;
continue; continue;

@ -0,0 +1,11 @@
import { test } from '../../test';
// A tag whose expression ends with a bare `/` at the end of the input used to
// make `find_matching_bracket` loop forever; it should error instead of hanging.
export default test({
error: {
code: 'unexpected_eof',
message: 'Unexpected end of input',
position: [12, 12]
}
});
Loading…
Cancel
Save