openrosa-xpath-evaluator
Advanced tools
Comparing version 2.0.12 to 2.0.13
@@ -13,4 +13,5 @@ { | ||
"rules": { | ||
"eol-last": ["error", "always"], | ||
"semi": [ "error", "always" ] | ||
} | ||
} |
@@ -6,2 +6,9 @@ Change Log | ||
[2.0.13] - 2022-10-26 | ||
---------------------- | ||
##### Fixed | ||
- Correctly evaluate absolute nodeset expressions with an attribute context node in any browser | ||
[2.0.12] - 2022-09-16 | ||
@@ -8,0 +15,0 @@ ---------------------- |
{ | ||
"name": "openrosa-xpath-evaluator", | ||
"version": "2.0.12", | ||
"version": "2.0.13", | ||
"description": "Wrapper for browsers' XPath evaluator with added support for OpenRosa extensions.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://enketo.org", |
@@ -115,2 +115,3 @@ const { handleOperation } = require('./utils/operation'); | ||
/** | ||
* @type {typeof document.evaluate} | ||
* @see https://developer.mozilla.org/en-US/docs/Web/API/Document/evaluate | ||
@@ -249,3 +250,14 @@ */ | ||
} else { | ||
pushToken(toInternalResult(wrapped.evaluate(expr, cN, nR, XPathResult.ANY_TYPE, null))); | ||
// This addresses a bug in Chrome and Safari, where an absolute | ||
// nodeset expression evaluated with an attribute contex node | ||
// does not evaluate to that nodeset as expected. Using the | ||
// attribute's owner document evaluates the expression correctly, | ||
// ensuring consistent behavior between Chrome, Safari and Firefox. | ||
const contextNode = ( | ||
cN?.nodeType === Node.ATTRIBUTE_NODE && expr.startsWith('/') | ||
? cN.ownerDocument | ||
: cN | ||
); | ||
pushToken(toInternalResult(wrapped.evaluate(expr, contextNode, nR, XPathResult.ANY_TYPE, null))); | ||
} | ||
@@ -252,0 +264,0 @@ |
@@ -6,4 +6,14 @@ (function registerDomGlobals() { | ||
}; | ||
Node.ELEMENT_NODE = 1; | ||
Object.assign(Node, { | ||
ELEMENT_NODE: 1, | ||
ATTRIBUTE_NODE: 2, | ||
TEXT_NODE: 3, | ||
CDATA_SECTION_NODE: 4, | ||
PROCESSING_INSTRUCTION_NODE: 7, | ||
COMMENT_NODE: 8, | ||
DOCUMENT_NODE: 9, | ||
DOCUMENT_TYPE_NODE: 10, | ||
DOCUMENT_FRAGMENT_NODE: 11, | ||
}); | ||
global.XPathResult = { | ||
@@ -10,0 +20,0 @@ ANY_TYPE: 0, |
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
391576
101
9370