added a terminal error when an XML document is found

This commit is contained in:
Mike Kamermans 2013-01-23 16:59:41 -05:00
Родитель 61b4092669
Коммит adaaf569dd
4 изменённых файлов: 43 добавлений и 1 удалений

Просмотреть файл

@ -108,6 +108,13 @@ var Slowparse = (function() {
}
return obj;
},
// These are document errors.
XML_DOCUMENT_DETECTED: function(parser, start, end) {
return {
start: start,
end: end
};
},
// These are HTML errors.
UNCLOSED_TAG: function(parser) {
return {
@ -1025,13 +1032,21 @@ var Slowparse = (function() {
// First we check to see if the beginning of our stream is
// an HTML5 doctype tag. We're currently quite strict and don't
// parse XHTML or other doctypes.
if (this.stream.match(this.html5Doctype, true, true))
if (this.stream.match("<?xml", false, true)) {
this.stream.eatWhile("[^\>]");
this.stream.next();
var token = this.stream.makeToken();
throw new ParseError("XML_DOCUMENT_DETECTED", this, token.interval.start, token.interval.end);
}
if (this.stream.match(this.html5Doctype, true, true)) {
this.domBuilder.fragment.parseInfo = {
doctype: {
start: 0,
end: this.stream.pos
}
};
}
// Next, we parse "tag soup", creating text nodes and diving into
// tags as we find them.

Просмотреть файл

@ -1,3 +1,8 @@
<!-- DOCUMENT ERRORS -->
<div class="error-msg XML_DOCUMENT_DETECTED">
<p>HTML5 does not use (or allow) an
<em data-highlight="{{start}},{{end}}">XML declaration</em>.</p>
</div>
<!-- HTML ERRORS -->
<div class="error-msg UNEXPECTED_CLOSE_TAG">
<p>The closing <code>&lt;/{{closeTag.name}}&gt;</code> tag

Просмотреть файл

@ -118,6 +118,18 @@ h1.error-category {
</div>
</div>
<h1 class="error-category">HTML Errors</h1>
<div class="test">
<script type="text/x-bad-html">
<?xml version="1.0"?><!doctype html5><p>xml document</p>
</script>
<script type="application/json">
{
"type": "XML_DOCUMENT_DETECTED",
"start": 0,
"end": 21
}
</script>
</div>
<div class="test">
<script type="text/x-bad-html">
hi</i>

Просмотреть файл

@ -27,6 +27,16 @@ test("parsing of valid DOCTYPE", function() {
});
});
test("terminate on XML document", function() {
var html = '<?xml version="1.0"?><!doctype html5><p>xml document</p>';
var result = Slowparse.HTML(document, html);
deepEqual(result.error, {
"type": "XML_DOCUMENT_DETECTED",
"start": 0,
"end": 21
});
});
test("parsing of misplaced DOCTYPE", function() {
var html = '<p>hi</p><!DOCTYPE html>';
var result = Slowparse.HTML(document, html);