mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Improve errors when scanning .html file (#3758)
This commit is contained in:
@@ -23,7 +23,7 @@ html_scanner = {
|
|||||||
|
|
||||||
var throwParseError = function (msg, overrideIndex) {
|
var throwParseError = function (msg, overrideIndex) {
|
||||||
var ret = new html_scanner.ParseError;
|
var ret = new html_scanner.ParseError;
|
||||||
ret.message = msg || "bad formatting in HTML template";
|
ret.message = msg || "bad formatting in template file";
|
||||||
ret.file = source_name;
|
ret.file = source_name;
|
||||||
var theIndex = (typeof overrideIndex === 'number' ? overrideIndex : index);
|
var theIndex = (typeof overrideIndex === 'number' ? overrideIndex : index);
|
||||||
ret.line = contents.substring(0, theIndex).split('\n').length;
|
ret.line = contents.substring(0, theIndex).split('\n').length;
|
||||||
@@ -39,7 +39,8 @@ html_scanner = {
|
|||||||
|
|
||||||
var match = rOpenTag.exec(rest);
|
var match = rOpenTag.exec(rest);
|
||||||
if (! match)
|
if (! match)
|
||||||
throwParseError(); // unknown text encountered
|
throwParseError("Expected <template>, <head>, or <body> tag" +
|
||||||
|
" in template file");
|
||||||
|
|
||||||
var matchToken = match[1];
|
var matchToken = match[1];
|
||||||
var matchTokenTagName = match[3];
|
var matchTokenTagName = match[3];
|
||||||
@@ -55,7 +56,7 @@ html_scanner = {
|
|||||||
// top-level HTML comment
|
// top-level HTML comment
|
||||||
var commentEnd = /--\s*>/.exec(rest);
|
var commentEnd = /--\s*>/.exec(rest);
|
||||||
if (! commentEnd)
|
if (! commentEnd)
|
||||||
throwParseError("unclosed HTML comment");
|
throwParseError("unclosed HTML comment in template file");
|
||||||
advance(commentEnd.index + commentEnd[0].length);
|
advance(commentEnd.index + commentEnd[0].length);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ Tinytest.add("templating - html scanner", function (test) {
|
|||||||
|
|
||||||
checkError(function() {
|
checkError(function() {
|
||||||
return html_scanner.scan("asdf");
|
return html_scanner.scan("asdf");
|
||||||
}, "formatting in HTML template", 1);
|
}, "Expected <template>, <head>, or <body> tag in template file", 1);
|
||||||
|
|
||||||
// body all on one line
|
// body all on one line
|
||||||
checkResults(
|
checkResults(
|
||||||
@@ -126,7 +126,7 @@ Tinytest.add("templating - html scanner", function (test) {
|
|||||||
// bad open tag
|
// bad open tag
|
||||||
checkError(function() {
|
checkError(function() {
|
||||||
return html_scanner.scan("\n\n\n<bodyd>\n Hello\n</body>");
|
return html_scanner.scan("\n\n\n<bodyd>\n Hello\n</body>");
|
||||||
}, "formatting in HTML template", 4);
|
}, "Expected <template>, <head>, or <body> tag in template file", 4);
|
||||||
checkError(function() {
|
checkError(function() {
|
||||||
return html_scanner.scan("\n\n\n\n<body foo=>\n Hello\n</body>");
|
return html_scanner.scan("\n\n\n\n<body foo=>\n Hello\n</body>");
|
||||||
}, "error in tag", 5);
|
}, "error in tag", 5);
|
||||||
@@ -167,4 +167,9 @@ Tinytest.add("templating - html scanner", function (test) {
|
|||||||
'pizza</template>');
|
'pizza</template>');
|
||||||
}, "error in tag", 1);
|
}, "error in tag", 1);
|
||||||
|
|
||||||
|
// unexpected <html> at top level
|
||||||
|
checkError(function() {
|
||||||
|
return html_scanner.scan('\n<html>\n</html>');
|
||||||
|
}, "Expected <template>, <head>, or <body> tag in template file", 2);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user