Skip to content

Commit 213c986

Browse files
authored
Merge pull request #435 from sveltejs/unclosed-script-infinite-loop
Prevent unclosed <script> causing infinite loop
2 parents 831ed54 + 05ea031 commit 213c986

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

src/parse/read/script.js

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export default function readScript ( parser, start, attributes ) {
77
const scriptStart = parser.index;
88
const scriptEnd = parser.template.indexOf( scriptClosingTag, scriptStart );
99

10+
if ( scriptEnd === -1 ) parser.error( `<script> must have a closing tag` );
11+
1012
const source = spaces( scriptStart ) + parser.template.slice( scriptStart, scriptEnd );
1113
parser.index = scriptEnd + scriptClosingTag.length;
1214

test/parser/index.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import assert from 'assert';
22
import * as fs from 'fs';
3-
import { svelte, exists } from '../helpers.js';
3+
import { svelte } from '../helpers.js';
44

55
describe( 'parse', () => {
66
fs.readdirSync( 'test/parser/samples' ).forEach( dir => {
77
if ( dir[0] === '.' ) return;
88

9-
const solo = exists( `test/parser/samples/${dir}/solo` );
9+
// add .solo to a sample directory name to only run that test
10+
const solo = /\.solo$/.test( dir );
1011

1112
if ( solo && process.env.CI ) {
12-
throw new Error( 'Forgot to remove `solo: true` from test' );
13+
throw new Error( `Forgot to remove '.solo' from test parser/samples/${dir}` );
1314
}
1415

1516
( solo ? it.only : it )( dir, () => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"message": "<script> must have a closing tag",
3+
"loc": {
4+
"line": 3,
5+
"column": 8
6+
},
7+
"pos": 34
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<h1>Hello {{name}}!</h1>
2+
3+
<script>

0 commit comments

Comments
 (0)