Bug #4958

saxon-js 2.1: Crash in Saxon.XPath.evaluate with certain predicates
0%
Description
I have isolated a crash condition that occurs using certain predicates. The problem can be seen in the code at https://github.com/Neuroboy23/saxon-test. This crash occurs in saxon-js 2.1. It does not occur in saxon-js 2.0.
Given this XML input:
<?xml version="1.0"?>
<objects>
<object name="foo" />
<object-ref name="foo" />
</objects>
And this code:
import Saxon from "saxon-js";
Saxon.XPath.evaluate(
"//*[ends-with(local-name(), '-ref')]",
document
);
The Saxon.XPath.evaluate
call above crashes with the following exception:
C:\dev\saxon-test\node_modules\saxon-js\SaxonJS2N.js:4065
y){return F.substring(0,y.length)===y}function q(F,y){return F.substring(F.length-y.length)===y}function z(F,y){return y&&(y=y.next())?y.toString():F.collation||Xd.getInheritedProperty(F,"defaultCollation")}function P(F,y){y=F?p(F,"http://www.w3.org/2013/collation/UCA")&&36<F.length?aa(F,F.substring(37),y):p(F,"http://saxon.sf.net/collation")&&29<F.length?aa(F,F.substring(30),y):y.fixed.qa.jd[F]:pa();if(!y)throw new M("Unrecognized collation "+F,"FOCH0002");return y}function aa(F,y){if(""===y)y=pa();
^
TypeError: Cannot read property 'jd' of undefined
at P (C:\dev\saxon-test\node_modules\←[4msaxon-js←[24m\SaxonJS2N.js:4065:394)
at Object.Ub (C:\dev\saxon-test\node_modules\←[4msaxon-js←[24m\SaxonJS2N.js:4073:213)
at ends-with (C:\dev\saxon-test\node_modules\←[4msaxon-js←[24m\SaxonJS2N.js:4274:469)
at C:\dev\saxon-test\node_modules\←[4msaxon-js←[24m\SaxonJS2N.js:4388:324
at jc.K [as g] (C:\dev\saxon-test\node_modules\←[4msaxon-js←[24m\SaxonJS2N.js:4387:511)
at jc.next (C:\dev\saxon-test\node_modules\←[4msaxon-js←[24m\SaxonJS2N.js:3975:180)
at lc.next (C:\dev\saxon-test\node_modules\←[4msaxon-js←[24m\SaxonJS2N.js:3976:69)
at lc.ba.forEachItem (C:\dev\saxon-test\node_modules\←[4msaxon-js←[24m\SaxonJS2N.js:3971:574)
at lc.ba.expand (C:\dev\saxon-test\node_modules\←[4msaxon-js←[24m\SaxonJS2N.js:3972:191)
at Object.Yd (C:\dev\saxon-test\node_modules\←[4msaxon-js←[24m\SaxonJS2N.js:3992:174)
at C:\dev\saxon-test\node_modules\←[4msaxon-js←[24m\SaxonJS2N.js:4381:382
at Object.J [as evaluate] (C:\dev\saxon-test\node_modules\←[4msaxon-js←[24m\SaxonJS2N.js:4357:15)
at Object.evaluate (C:\dev\saxon-test\node_modules\←[4msaxon-js←[24m\SaxonJS2N.js:4605:248)
at file:///C:/dev/saxon-test/index.js:17:33
History
#1
Updated by Michael Gunter 20 days ago
For completeness' sake, here's the same code block above with the addition of the code to load the xml file the file test.xml
. The crash with this code is the same as above.
import Saxon from "saxon-js";
const document = await Saxon.getResource({
file: "test.xml",
type: "xml"
});
Saxon.XPath.evaluate(
"//*[ends-with(local-name(), '-ref')]",
document
);
#2
Updated by Michael Kay 20 days ago
Using a top--level "await" like this is a very new feature in Node, and not one that we've tested as far as I'm aware. Does it still fail if you use the more traditional structure
Saxon.getResource({
file: "test.xml",
type: "xml"
}).then(document =>
Saxon.XPath.evaluate(
"//*[ends-with(local-name(), '-ref')]",
document
);
?
#3
Updated by Michael Gunter 19 days ago
Yes. The same error is thrown when using .then
instead of await
. I have updated the code on https://github.com/Neuroboy23/saxon-test accordingly.
#4
Updated by Michael Gunter 19 days ago
To be clear: A concise demonstrable script is at https://github.com/Neuroboy23/saxon-test/blob/master/index.js
#5
Updated by Norm Tovey-Walsh 14 days ago
- Status changed from New to In Progress
This appears to be caused by an error in the way the context is initialized for evaluating XPath expressions. The context is missing the fixed options (hence the cannot read property ... of undefined
error) and it needs to access the collation for the ends-with
function. Now I just need to work out how and where that's supposed to happen.
Please register to edit this issue
Also available in: Atom PDF Tracking page