зеркало из https://github.com/mozilla/slowparse.git
add a MISSING_CLOSING_TAG_NAME
This commit is contained in:
Родитель
ec6336d49f
Коммит
038d1200e2
24
slowparse.js
24
slowparse.js
|
@ -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
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче