add a MISSING_CLOSING_TAG_NAME

This commit is contained in:
Pomax 2017-09-27 14:05:01 -07:00
Родитель ec6336d49f
Коммит 038d1200e2
4 изменённых файлов: 57 добавлений и 0 удалений

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

@ -973,11 +973,18 @@ module.exports = (function(){
};
var openTagName = this.domBuilder.currentNode.nodeName.toLowerCase();
if (closeTagName != openTagName) {
// Are we dealing with a rogue </ here?
if (closeTagName === "") {
throw new ParseError("MISSING_CLOSING_TAG_NAME", token, openTagName, this.domBuilder.currentNode.closeWarnings);
}
// Are we dealing with a tag that is closed in the source,
// even though based on DOM parsing it already got closed?
if (this.domBuilder.currentNode.closeWarnings) {
throw new ParseError("MISMATCHED_CLOSE_TAG_DUE_TO_EARLIER_AUTO_CLOSING", this, closeTagName, token);
}
// This is just a regular old mismatched closing tag.
throw new ParseError("MISMATCHED_CLOSE_TAG", this, openTagName, closeTagName, token);
}
this._parseEndCloseTag();
@ -1477,6 +1484,23 @@ module.exports = (function() {
cursor: openTag.start
};
},
MISSING_CLOSING_TAG_NAME: function(token, openTagName, autocloseWarnings) {
var openTag = this._combine({
name: openTagName
}, token.interval);
if (autocloseWarnings) {
var tag = autocloseWarnings[0];
openTag = this._combine({
name: tag.tagName
}, tag.parseInfo.openTag);
}
return {
openTag: openTag,
cursor: token.interval.start
};
},
UNEXPECTED_CLOSE_TAG: function(parser, closeTagName, token) {
var closeTag = this._combine({
name: closeTagName

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

@ -315,11 +315,18 @@ module.exports = (function(){
};
var openTagName = this.domBuilder.currentNode.nodeName.toLowerCase();
if (closeTagName != openTagName) {
// Are we dealing with a rogue </ here?
if (closeTagName === "") {
throw new ParseError("MISSING_CLOSING_TAG_NAME", token, openTagName, this.domBuilder.currentNode.closeWarnings);
}
// Are we dealing with a tag that is closed in the source,
// even though based on DOM parsing it already got closed?
if (this.domBuilder.currentNode.closeWarnings) {
throw new ParseError("MISMATCHED_CLOSE_TAG_DUE_TO_EARLIER_AUTO_CLOSING", this, closeTagName, token);
}
// This is just a regular old mismatched closing tag.
throw new ParseError("MISMATCHED_CLOSE_TAG", this, openTagName, closeTagName, token);
}
this._parseEndCloseTag();

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

@ -42,6 +42,23 @@ module.exports = (function() {
cursor: openTag.start
};
},
MISSING_CLOSING_TAG_NAME: function(token, openTagName, autocloseWarnings) {
var openTag = this._combine({
name: openTagName
}, token.interval);
if (autocloseWarnings) {
var tag = autocloseWarnings[0];
openTag = this._combine({
name: tag.tagName
}, tag.parseInfo.openTag);
}
return {
openTag: openTag,
cursor: token.interval.start
};
},
UNEXPECTED_CLOSE_TAG: function(parser, closeTagName, token) {
var closeTag = this._combine({
name: closeTagName

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

@ -831,6 +831,15 @@ module.exports = function(Slowparse, window, document, validators) {
});
});
test("testing </ and auto-closed tags", function () {
var html = '<body><div><p><h1>lol</h1></</div></body>';
var result = parse(html);
equal(result.error, {
type: 'MISSING_CLOSING_TAG_NAME',
openTag: { name: 'p', start: 11, end: 14 },
cursor: 26
});
});
// specifically CSS testing