openrosa-xpath-evaluator
Advanced tools
Comparing version 1.2.2 to 1.3.0
{ | ||
"name": "openrosa-xpath-evaluator", | ||
"version": "1.2.2", | ||
"version": "1.3.0", | ||
"description": "Wrapper for browsers' XPath evaluator with added support for OpenRosa extensions.", | ||
"main": "src/openrosa-xpath.js", | ||
"scripts": { | ||
"test": "./node_modules/karma/bin/karma start karma.config.js --single-run" | ||
"jshint": "jshint src/*.js test/*.js", | ||
"test": "./node_modules/karma/bin/karma start karma.config.js --single-run", | ||
"travis": "npm run jshint && npm test" | ||
}, | ||
@@ -9,0 +11,0 @@ "author": "Alex", |
@@ -56,10 +56,7 @@ Openrosa XForms Evaluator | ||
* `ancestor::author[parent::book][1]` | ||
## Unsupported XPath expressions: | ||
* `*/*` | ||
* `*[@specialty]` | ||
* `@*` | ||
* `@my:*` | ||
* `@*` | ||
* `my:*` | ||
* `author[degree and award]` | ||
@@ -84,3 +81,2 @@ * `author[(degree or award) and publication]` | ||
* `degree[@from != "Harvard"]` | ||
* `my:*` | ||
* `p/text()[2]` | ||
@@ -91,1 +87,6 @@ * `price[@intl = "Canada"]` | ||
* `(x/y)[1]` | ||
## Unsupported XPath expressions: | ||
(Add any examples of known-unsupported expressions here and to `test/extended-xpath.spec.js`.) |
@@ -150,3 +150,3 @@ /* | ||
nextChar = function() { | ||
if(i < input.length -1) return input.charAt(i+1); | ||
return input.charAt(i+1); | ||
}, | ||
@@ -170,2 +170,8 @@ finaliseNum = function() { | ||
var c = input.charAt(i); | ||
if(cur.sq) { | ||
cur.v += c; | ||
if(c === ']') --cur.sq; | ||
else if(c === '[') ++cur.sq; | ||
continue; | ||
} | ||
if(cur.t === 'str') { | ||
@@ -205,2 +211,10 @@ if(c === cur.quote) { | ||
case ')': | ||
if(nextChar() === '[') { | ||
// collapse the stack, and let the native evaluator handle this... | ||
var tail = stack.pop(); | ||
tail.v = tail.v + '(' + cur.v + c; | ||
tail.t = '?'; | ||
cur = tail; | ||
break; | ||
} | ||
if(cur.v !== '') handleXpathExpr(); | ||
@@ -222,10 +236,9 @@ backtrack(); | ||
break; | ||
case ';': | ||
if(nextChar() !== '=') { | ||
switch(cur.v) { | ||
case '<': pushOp('<'); continue; | ||
case '>': pushOp('>'); continue; | ||
} | ||
case '*': | ||
if(c === '*' && (cur.v !== '' || peek().tokens.length === 0)) { | ||
cur.v += c; | ||
} else { | ||
pushOp(c); | ||
} | ||
/* falls through */ | ||
break; | ||
case '-': | ||
@@ -235,12 +248,12 @@ if(cur.v !== '') { | ||
cur.v += c; | ||
break; | ||
} else if(peek().tokens.length === 0 || prevToken().t === 'op') { | ||
// -ve number | ||
cur = { t:'num', string:'-' }; | ||
break; | ||
} // else it's `-` operator | ||
/* falls through */ | ||
} else { | ||
pushOp(c); | ||
} | ||
break; | ||
case '=': | ||
if(c === '=' && (cur.v === '<' || cur.v === '<' || | ||
cur.v === '>' || cur.v === '>' || cur.v === '!')) { | ||
if(cur.v === '<' || cur.v === '<' || | ||
cur.v === '>' || cur.v === '>' || cur.v === '!') { | ||
cur.v += c; | ||
@@ -252,34 +265,21 @@ switch(cur.v) { | ||
} | ||
break; | ||
} else { | ||
pushOp(c); | ||
} | ||
break; | ||
case ';': | ||
switch(cur.v) { | ||
case '<': c = '<'; break; | ||
case '>': c = '>'; break; | ||
default: cur.v += c; continue; | ||
} | ||
/* falls through */ | ||
case '>': | ||
case '<': | ||
if((c === '<' || c === '>') && nextChar() === '=') { | ||
cur.v += c; break; | ||
if(nextChar() === '=') { | ||
cur.v = c; break; | ||
} | ||
/* falls through */ | ||
case '+': | ||
case '*': | ||
// > If there is a preceding token and the preceding token is not one | ||
// > of @, ::, (, [, , or an Operator, then a * must be recognized as | ||
// > a MultiplyOperator and an NCName must be recognized as an | ||
// > OperatorName. | ||
// > – https://www.w3.org/TR/xpath/#exprlex | ||
if(cur.v !== '') { | ||
switch(cur.v.charAt(cur.v.length-1)) { | ||
case ':': | ||
if(cur.v.length < 2 || cur.v.charAt(cur.v.length-2) != ':') { | ||
// * is a MultiplyOperator! | ||
break; | ||
} | ||
/* falls through */ | ||
case '/': | ||
cur.v += c; | ||
continue; | ||
} | ||
// * is a MultiplyOperator! | ||
handleXpathExpr(); | ||
} | ||
peek().tokens.push({ t:'op', v:c }); | ||
pushOp(c); | ||
break; | ||
@@ -296,2 +296,5 @@ case ' ': | ||
break; | ||
case '[': | ||
cur.sq = (cur.sq || 0) + 1; | ||
/* falls through */ | ||
default: | ||
@@ -298,0 +301,0 @@ cur.v += c; |
@@ -164,8 +164,7 @@ define(['src/extended-xpath', 'chai', 'lodash'], function(ExtendedXpathEvaluator, chai, _) { | ||
'../../some-path', | ||
], | ||
trickyStandardXpath_unsupported = [ | ||
'*/*', | ||
'*[@specialty]', | ||
'@*', | ||
'@my:*', | ||
'@*', | ||
'my:*', | ||
'author[degree and award]', | ||
@@ -190,3 +189,2 @@ 'author[(degree or award) and publication]', | ||
'degree[@from != "Harvard"]', | ||
'my:*', | ||
'p/text()[2]', | ||
@@ -198,2 +196,4 @@ 'price[@intl = "Canada"]', | ||
], | ||
trickyStandardXpath_unsupported = [ | ||
], | ||
xp = { | ||
@@ -309,3 +309,5 @@ str: function(v) { return { t:'str', v:v }; }, | ||
} catch(e) { | ||
assert.equal(e.message.indexOf('Too many tokens.'), 0); | ||
if(e.message.indexOf('Too many tokens.') === 0) { | ||
// expected | ||
} else throw e; | ||
} | ||
@@ -312,0 +314,0 @@ }); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2447
90
149169
14