Skip to content

Commit

Permalink
Fixed case sensitive xpath selector with namespace URLs with captial
Browse files Browse the repository at this point in the history
letters
bbyars#243
  • Loading branch information
bbyars committed May 28, 2017
1 parent ccd415a commit 8b51bbd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/models/predicates.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,19 @@ function orderIndependent (possibleArray) {
}
}

function transformObject (obj, transform) {
Object.keys(obj).forEach(function (key) {
obj[key] = transform(obj[key]);
});
return obj;
}

function selectXPath (config, caseTransform, encoding, text) {
var xpath = require('./xpath'),
combinators = require('../util/combinators'),
ns = normalize(config.ns, {}, 'utf8'),
ns = transformObject(config.ns || {}, caseTransform),
selectFn = combinators.curry(xpath.select, caseTransform(config.selector), ns, text);

return orderIndependent(select('xpath', selectFn, encoding));
}

Expand Down
13 changes: 13 additions & 0 deletions test/models/predicates/xpathTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,19 @@ describe('predicates', function () {
assert.ok(predicates.evaluate(predicate, request));
});

it('#equals should be true if caseSensitive and namespace has capital letters in URL', function () {
var predicate = {
equals: { field: 'Harry Potter' },
caseSensitive: true,
xpath: {
selector: '//bookml:title/text()',
ns: { bookml: 'http://EXAMPLE.COM/book' }
}
},
request = { field: '<book xmlns:bookml="http://EXAMPLE.COM/book"><bookml:title>Harry Potter</bookml:title></book>' };
assert.ok(predicates.evaluate(predicate, request));
});

it('#endsWith should be false if aliased namespace match does not end with predicate', function () {
var predicate = {
endsWith: { field: 'Harry' },
Expand Down

0 comments on commit 8b51bbd

Please sign in to comment.