Project

Profile

Help

Bug #4958

closed

saxon-js 2.1: Crash in Saxon.XPath.evaluate with certain predicates

Added by Michael Gunter almost 3 years ago. Updated almost 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
2021-04-01
Due date:
% Done:

100%

Estimated time:
Applies to JS Branch:
2
Fix Committed on JS Branch:
2
Fixed in JS Release:
SEF Generated with:
Platforms:
Company:
-
Contact person:
-
Additional contact persons:
-

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
Actions #1

Updated by Michael Gunter almost 3 years 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
);
Actions #2

Updated by Michael Kay almost 3 years 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
  );

?

Actions #3

Updated by Michael Gunter almost 3 years 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.

Actions #4

Updated by Michael Gunter almost 3 years ago

To be clear: A concise demonstrable script is at https://github.com/Neuroboy23/saxon-test/blob/master/index.js

Actions #5

Updated by Norm Tovey-Walsh almost 3 years 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.

Actions #6

Updated by Norm Tovey-Walsh almost 3 years ago

  • Status changed from In Progress to Resolved

I've committed a fix which resolves this issue. The static context was missing the collations when using the XPath evaluate function.

Actions #10

Updated by Michael Gunter almost 3 years ago

What's the ETA for public deployment? (I'm a software developer myself, and I understand that question is annoying and sometimes hard to answer. But as a first-time Saxonica/Saxon-JS user, I don't know your organization yet.)

Actions #11

Updated by Norm Tovey-Walsh almost 3 years ago

There were a couple of items that didn't make it into the 2.1 release that have now been finished, so I'd like to do another release as soon as it's practical. Several bugs have been reported against 2.1 and we're working on those now. It makes sense to fix those first, I think.

None of which actually answers your question.

"I'd be pleased if we got another release out before June." But that's not a promise of any sort. :-)

Actions #12

Updated by Norm Tovey-Walsh almost 3 years ago

  • Status changed from Resolved to Closed

This issue has been resolved in the Saxon 2.2 maintenance release.

Actions #13

Updated by Debbie Lockett almost 3 years ago

  • % Done changed from 0 to 100
  • Fixed in JS Release set to Saxon-JS 2.2
  • Fix Committed on JS Branch 2 added
Actions #14

Updated by Debbie Lockett almost 3 years ago

  • Applies to JS Branch 2 added

Please register to edit this issue

Also available in: Atom PDF Tracking page