Skip to content

Commit

Permalink
Merge pull request #435 from sveltejs/unclosed-script-infinite-loop
Browse files Browse the repository at this point in the history
Prevent unclosed <script> causing infinite loop
  • Loading branch information
Rich-Harris authored Apr 2, 2017
2 parents 831ed54 + 05ea031 commit 213c986
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/parse/read/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export default function readScript ( parser, start, attributes ) {
const scriptStart = parser.index;
const scriptEnd = parser.template.indexOf( scriptClosingTag, scriptStart );

if ( scriptEnd === -1 ) parser.error( `<script> must have a closing tag` );

const source = spaces( scriptStart ) + parser.template.slice( scriptStart, scriptEnd );
parser.index = scriptEnd + scriptClosingTag.length;

Expand Down
7 changes: 4 additions & 3 deletions test/parser/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import assert from 'assert';
import * as fs from 'fs';
import { svelte, exists } from '../helpers.js';
import { svelte } from '../helpers.js';

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

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

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

( solo ? it.only : it )( dir, () => {
Expand Down
8 changes: 8 additions & 0 deletions test/parser/samples/error-script-unclosed/error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"message": "<script> must have a closing tag",
"loc": {
"line": 3,
"column": 8
},
"pos": 34
}
3 changes: 3 additions & 0 deletions test/parser/samples/error-script-unclosed/input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>Hello {{name}}!</h1>

<script>

0 comments on commit 213c986

Please sign in to comment.