Permalink
Browse files

Check for empty tags is now case-insensitive. Makes jsdom pass the W3…

…C test-suite which use upper-case tags.
  • Loading branch information...
1 parent 00fbea9 commit 67dc4c286685152f783fbcaf192646f8a197ff76 Felix Gnass committed Nov 10, 2010
Showing with 12 additions and 3 deletions.
  1. +12 −3 lib/node-htmlparser.js
View
@@ -598,6 +598,15 @@ function DefaultHandler (callback, options) {
return;
this._callback(error, this.dom);
}
+
+ DefaultHandler.prototype.isEmptyTag = function(element) {
+ var name = element.name.toLowerCase();
+ if (name.charAt(0) == '/') {
+ name = name.substring(1);
+ }
+ return this._options.enforceEmptyTags && !!DefaultHandler._emptyTags[name];
+ };
+
DefaultHandler.prototype.handleElement = function DefaultHandler$handleElement (element) {
if (this._done)
this.handleCallback(new Error("Writing to the handler after done() called is not allowed without a reset()"));
@@ -613,7 +622,7 @@ function DefaultHandler (callback, options) {
if (element.type != ElementType.Text && element.type != ElementType.Comment && element.type != ElementType.Directive) {
if (element.name.charAt(0) != "/") { //Ignore closing tags that obviously don't have an opening tag
this.dom.push(element);
- if (!this._options.enforceEmptyTags || !DefaultHandler._emptyTags[element.name]) { //Don't add tags to the tag stack that can't have children
+ if (!this.isEmptyTag(element)) { //Don't add tags to the tag stack that can't have children
this._tagStack.push(element);
}
}
@@ -629,7 +638,7 @@ function DefaultHandler (callback, options) {
//This is a closing tag, scan the tagStack to find the matching opening tag
//and pop the stack up to the opening tag's parent
var baseName = element.name.substring(1);
- if (!this._options.enforceEmptyTags || !DefaultHandler._emptyTags[baseName]) {
+ if (!this.isEmptyTag(element)) {
var pos = this._tagStack.length - 1;
while (pos > -1 && this._tagStack[pos--].name != baseName) { }
if (pos > -1 || this._tagStack[0].name == baseName)
@@ -641,7 +650,7 @@ function DefaultHandler (callback, options) {
if (!this._tagStack.last().children)
this._tagStack.last().children = [];
this._tagStack.last().children.push(element);
- if (!this._options.enforceEmptyTags || !DefaultHandler._emptyTags[element.name]) //Don't add tags to the tag stack that can't have children
+ if (!this.isEmptyTag(element)) //Don't add tags to the tag stack that can't have children
this._tagStack.push(element);
}
}

0 comments on commit 67dc4c2

Please sign in to comment.