Skip to content

Commit

Permalink
Get attributes' string value using Attr.value, with Attr.nodeValue as…
Browse files Browse the repository at this point in the history
… fallback
  • Loading branch information
JLRishe committed Jan 26, 2016
1 parent 714f121 commit ca913d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 12 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,4 +717,16 @@ module.exports = {

test.done();
}

// /~https://github.com/goto100/xpath/issues/32
,'supports contains() function on attributes': function (test) {
var doc = new dom().parseFromString("<books><book title='Harry Potter and the Philosopher\"s Stone' /><book title='Harry Potter and the Chamber of Secrets' /></books>"),
andTheBooks = xpath.select("/books/book[contains(@title, ' ')]", doc),
secretBooks = xpath.select("/books/book[contains(@title, 'Secrets')]", doc);

assert.equal(andTheBooks.length, 2);
assert.equal(secretBooks.length, 1);

test.done();
}
}
5 changes: 4 additions & 1 deletion xpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -2974,6 +2974,9 @@ XNodeSet.prototype.stringForNode = function(n) {
if (n.nodeType == 1 /*Node.ELEMENT_NODE*/ || n.nodeType === 11 /*Node.DOCUMENT_FRAGMENT*/) {
return this.stringForNodeRec(n);
}
if (n.nodeType === 2 /* Node.ATTRIBUTE_NODE */) {
return n.value || n.nodeValue;
}
if (n.isNamespaceNode) {
return n.namespace;
}
Expand Down Expand Up @@ -3523,7 +3526,7 @@ Functions.contains = function() {
}
var s1 = arguments[1].evaluate(c).stringValue();
var s2 = arguments[2].evaluate(c).stringValue();
return new XBoolean(s1.indexOf(s2) != -1);
return new XBoolean(s1.indexOf(s2) !== -1);
};

Functions.substringBefore = function() {
Expand Down

0 comments on commit ca913d9

Please sign in to comment.