fix readUntil infinite loop bug

pull/31/head
Rich-Harris 8 years ago
parent b233bbf404
commit 817d371826

@ -94,8 +94,19 @@ export default function parse ( template ) {
},
readUntil ( pattern ) {
const match = pattern.exec( this.template.slice( this.index ) );
return this.template.slice( this.index, match ? ( this.index += match.index ) : this.template.length );
if ( this.index >= this.template.length ) parser.error( 'Unexpected end of input' );
const start = this.index;
const match = pattern.exec( this.template.slice( start ) );
if ( match ) {
const start = this.index;
this.index = start + match.index;
return this.template.slice( start, this.index );
}
this.index = this.template.length;
return this.template.slice( start );
},
remaining () {

@ -0,0 +1,8 @@
{
"message": "Unexpected end of input",
"loc": {
"line": 1,
"column": 2
},
"pos": 2
}

@ -0,0 +1,8 @@
{
"message": "Unexpected end of input",
"loc": {
"line": 1,
"column": 1
},
"pos": 1
}

@ -1,8 +1,8 @@
{
"message": "Unexpected end of input",
"loc": {
"line": 2,
"column": 0
"line": 1,
"column": 5
},
"pos": 6
"pos": 5
}

@ -32,7 +32,7 @@ describe( 'svelte', () => {
const solo = exists( `test/parser/${dir}/solo` );
( solo ? it.only : it )( dir, () => {
const input = fs.readFileSync( `test/parser/${dir}/input.html`, 'utf-8' );
const input = fs.readFileSync( `test/parser/${dir}/input.html`, 'utf-8' ).replace( /\s+$/, '' );
try {
const actual = parse( input );

Loading…
Cancel
Save