New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parsed XML doc's XPath queries fail with upper case attributes #2530
Comments
We've had a todo for a long time to replace our ancient hand-rolled xpath implementation with a maintained third-party one. That's probably the best route to fixing this, although a spot-fix PR with a test would also be acceptable. |
Hi, any updates? |
@domenic would it make sense for someone (me, if I can find the time) to try prepare a PR to use a third-party library such as https://github.com/google/wicked-good-xpath ? |
Yes, anything that passes the existing test suite (and ideally adds new ones) would be welcome. |
Unfortunately wicked-good-xpath currently fails our test suite from what I remember. I tried working on it in google/wicked-good-xpath#41, but introduced a different bug in that one blocking merge. |
Thanks for the quick replies - I thought there must be a catch. Probably won't have enough spare time for this, but I can take a look. |
While writing some unit tests using xpaths, I stumbled upon some limitations of jsdom (the dom implementation used in the tests): It e.g. does not support upper case characters within either the xpath, which is something we need for e.g. the eIds (see also: jsdom/jsdom#2530). Sadly the support for xpaths is even worse with happy-dom :/ I therefore decided to mock the implementation of the method for evaluating xpaths in the unit tests using the [xpath](https://www.npmjs.com/package/xpath) library. RISDEV-3932
While writing some unit tests using xpaths, I stumbled upon some limitations of jsdom (the dom implementation used in the tests): It e.g. does not support upper case characters within either the xpath, which is something we need for e.g. the eIds (see also: jsdom/jsdom#2530). Sadly the support for xpaths is even worse with happy-dom :/ I therefore decided to mock the implementation of the method for evaluating xpaths in the unit tests using the [xpath](https://www.npmjs.com/package/xpath) library. RISDEV-3932
While writing some unit tests using xpaths, I stumbled upon some limitations of jsdom (the dom implementation used in the tests): It e.g. does not support upper case characters within either the xpath, which is something we need for e.g. the eIds (see also: jsdom/jsdom#2530). Sadly the support for xpaths is even worse with happy-dom :/ I therefore decided to mock the implementation of the method for evaluating xpaths in the unit tests using the [xpath](https://www.npmjs.com/package/xpath) library. RISDEV-3932
While writing some unit tests using xpaths, I stumbled upon some limitations of jsdom (the dom implementation used in the tests): It e.g. does not support upper case characters within either the xpath, which is something we need for e.g. the eIds (see also: jsdom/jsdom#2530). Sadly the support for xpaths is even worse with happy-dom :/ I therefore decided to mock the implementation of the method for evaluating xpaths in the unit tests using the [xpath](https://www.npmjs.com/package/xpath) library. RISDEV-3932
Basic info:
When using XPath to query/evaluate an XML document generated by JSDOM's DOMParser, the attribute part of the query seems to be forced to lower case, making it impossible to query for attributes that contain upper cased characters.
For example, given the following document:
A query for
//*[@Foo="bar"]
(or//*[@foo="bar"]
for that matter) returns no matches, however given this document instead with lower case attributes:Now with this new document,
//*[@foo="bar"]
(and the upper case equivalent//*[@Foo="bar"]
) successfully find the match.I have found a similar issue from a long time ago (#651) that was fixed by introducing Saxes to parse XML documents separately from HTML documents, however currently at the parsing level everything seems to be parsed correctly (e.g. the attributes retain their case). It is at the XPath evaluation level that the query seems to be lower cased.
I have tried narrowing down where the error might be occurring, and have reached
jsdom/lib/jsdom/level3/xpath.js
Line 1659 in b83783d
Setting that
shouldLowerCase
value tofalse
fixes for my use case, but I am not aware of what implications that has for the rest of the XPath implementation.Minimal reproduction case
How does similar code behave in browsers?
https://jsbin.com/qegifaqumi/2/edit?js,console
The XPath query is case sensitive and can match against nodes with attributes with upper case characters.
The text was updated successfully, but these errors were encountered: