diff --git a/compiler/parse/index.js b/compiler/parse/index.js index 80a9c44855..b988dd9ee2 100644 --- a/compiler/parse/index.js +++ b/compiler/parse/index.js @@ -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 () { diff --git a/test/parser/error-unexpected-end-of-input-b/error.json b/test/parser/error-unexpected-end-of-input-b/error.json new file mode 100644 index 0000000000..c3ddfee08d --- /dev/null +++ b/test/parser/error-unexpected-end-of-input-b/error.json @@ -0,0 +1,8 @@ +{ + "message": "Unexpected end of input", + "loc": { + "line": 1, + "column": 2 + }, + "pos": 2 +} diff --git a/test/parser/error-unexpected-end-of-input-b/input.html b/test/parser/error-unexpected-end-of-input-b/input.html new file mode 100644 index 0000000000..65504cdfb9 --- /dev/null +++ b/test/parser/error-unexpected-end-of-input-b/input.html @@ -0,0 +1 @@ + { 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 );