Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix exception when getAttribute or removeAttribute run into removed a…

…ttributes

because removeAttribute only nullifies the entry in the this.attrs
array, we may still run into it. this makes getAttribute and
setAttribute handle those cases.
  • Loading branch information...
commit 9cbebf5e65556b7ca4027333f0a50295d18b7d45 1 parent 77fadc1
@daaku daaku authored tj committed
Showing with 14 additions and 4 deletions.
  1. +3 −3 lib/nodes/tag.js
  2. +11 −1 test/jade.test.js
View
6 lib/nodes/tag.js
@@ -51,7 +51,7 @@ Tag.prototype.setAttribute = function(name, val){
Tag.prototype.removeAttribute = function(name){
for (var i = 0, len = this.attrs.length; i < len; ++i) {
- if (this.attrs[i].name == name) {
+ if (this.attrs[i] && this.attrs[i].name == name) {
delete this.attrs[i];
}
}
@@ -67,7 +67,7 @@ Tag.prototype.removeAttribute = function(name){
Tag.prototype.getAttribute = function(name){
for (var i = 0, len = this.attrs.length; i < len; ++i) {
- if (this.attrs[i].name == name) {
+ if (this.attrs[i] && this.attrs[i].name == name) {
return this.attrs[i].val;
}
}
@@ -77,4 +77,4 @@ Tag.prototype.getAttribute = function(name){
* Inherit from `Node`.
*/
-Tag.prototype.__proto__ = Node.prototype;
+Tag.prototype.__proto__ = Node.prototype;
View
12 test/jade.test.js
@@ -872,5 +872,15 @@ module.exports = {
assert.equal(
"Jade:1\n 1. 'p= asdf'\n\nasdf is not defined",
err.message);
+ },
+
+ 'test null attrs on tag': function(assert){
+ var tag = new jade.nodes.Tag('a'),
+ name = 'href',
+ val = '"/"';
+ tag.setAttribute(name, val)
+ assert.equal(tag.getAttribute(name), val)
+ tag.removeAttribute(name)
+ assert.isUndefined(tag.getAttribute(name))
}
-};
+};

0 comments on commit 9cbebf5

Please sign in to comment.
Something went wrong with that request. Please try again.