Permalink
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...
1 parent 77fadc1 commit 9cbebf5e65556b7ca4027333f0a50295d18b7d45 @daaku daaku committed with tj Jan 31, 2011
Showing with 14 additions and 4 deletions.
  1. +3 −3 lib/nodes/tag.js
  2. +11 −1 test/jade.test.js
View
@@ -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
@@ -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.