question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect result when running the same xpath against a similar document

See original GitHub issue

See below example test.

const nameSpaceDocument = new slimdom.Document();
const namespaceElement = nameSpaceDocument.createElementNS("http://test.com", "name");
namespaceElement.textContent = 'name1'
nameSpaceDocument.appendChild(namespaceElement);

chai.assert.equal(evaluateXPathToString('/name/text()',	nameSpaceDocument), 'name1')

const slimdomDocument = new slimdom.Document();
const nameElement = slimdomDocument.createElement("name");
nameElement.textContent = 'name2'
slimdomDocument.appendChild(nameElement);

chai.assert.equal(evaluateXPathToString('/name/text()',	slimdomDocument), 'name2')

The first document includes a namespace on the name element. The second document does not. The second assertion will fail, however if you change the order of the assertions it works as expected. If you change the second xpath to just be ‘/name’ it also works as expected. Looks to be a caching issue?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
DrRataplancommented, Mar 4, 2020

Found it, when compiling an expression, we try to return a fully cached expression if both the expression string the static contexts match another run. This fails here. We then try to get a ‘half compiled’ result, which can occur when someone just asked for a bucket of a selector, but did not execute it. Getting the bucket of a selector does not require static compilation, but does require a ‘normal’ compilation. However, this mistakingly gets any compilation result. See https://github.com/FontoXML/fontoxpath/blob/master/src/parsing/compiledExpressionCache.ts#L129, which in the end does https://github.com/FontoXML/fontoxpath/blob/master/src/parsing/compiledExpressionCache.ts#L46.

The fix would be to only use the ‘halfcompiled’ cache here.

0reactions
ymorcommented, Mar 6, 2020

Hi, Yes it is now working as expected. Thanks for the quick turnaround!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Failed to execute 'evaluate' on 'Document' error using XPath ...
no such element: Unable to locate element is a different error from your initial SyntaxError which seems to have got resolved now. Feel...
Read more >
Complete Guide For Using XPath In Selenium With Examples
XPath in Selenium allows you to run queries against localized documents even if they don't share the same base tag name. How do...
Read more >
Introduction to using XPath in JavaScript - MDN Web Docs
This method evaluates XPath expressions against an XML based document (including HTML documents), and returns a XPathResult object, which can be ...
Read more >
Xpath syntax error when I use `contains` for `classname` and ...
To achieve this I am trying something like this: ... following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string ...
Read more >
XPath and XQuery Functions and Operators 3.1 - W3C
This section is concerned with the question of whether two calls on a function, with the same arguments, may produce different results. [ ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found