diff --git a/src/models/predicates.js b/src/models/predicates.js index 8fdf52c84..a36d1fa45 100644 --- a/src/models/predicates.js +++ b/src/models/predicates.js @@ -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)); } diff --git a/test/models/predicates/xpathTest.js b/test/models/predicates/xpathTest.js index 9c9ee597b..6023ad41c 100644 --- a/test/models/predicates/xpathTest.js +++ b/test/models/predicates/xpathTest.js @@ -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: 'Harry Potter' }; + 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' },