Namespaces are handled slightly wrong#41
Conversation
|
Added a PR which fixes at least one of the issues. I haven't exactly debugged where the other one originates from yet. |
|
@Sebmaster Cool thanks. Are you going to work on the second part? |
|
Yeah, I'll probably have some time tomorrow so I'll try to dig into it again. |
|
@Sebmaster Great. Thanks for looking into this! |
|
Okay got to it right now. This should be it for the namespace related stuff. |
|
@Sebmaster Thanks for the PR. Just want to you to know that I'm working on solving #20 first before merging this, so that we can make sure the tests are still passing. |
|
I noticed with this PR its still not returning valid results for empty or null namespaces (no prefix). Might I suggest letting the So at node.js:268 make it read: var nodes = node.getElementsByTagName(test.getName());
goog.array.forEach(nodes, function(node) {
if (test.matches(node) && wgxpath.Node.attrMatches(node, attrName, attrValue)) {
nodeset.add(node);
}
});Additionally this change in nameTest.js: if (this.namespaceUri_ == wgxpath.NameTest.HTML_NAMESPACE_URI_) {
this.name_ = this.name_.toLowerCase();
}Causes case sensitive node names to not match if there parsed under a document which has no namespace. I changed To use the plunker just comment out one of the script includes at the top of index.html and uncomment the on you want to test. The plunker runs 6 tests on similar documents but with different cases and namespaces. I took the code from @ScottFreeCode issue and modified it a bit. I compares the native browser implementations xpath result to wgxpaths. If they resulted in different things then it shows them as red. |
How are you reproducing this? XML doc without
name_ has always been lower-cased before. Do you mean you rely on tags without namespace to always be lowercased? That doesn't sound right, case insensitivity is a HTML thing afaik. Oh, just saw the plunker, I'll take a look. |
|
Sorry I should have posted some sample code with my comments. The plunker is there but ill add some code here to narrow it down and help snapshot the relevant info for this conversation in case that plunker goes away.
Exactly no xmlns, lets look at this code // running wgxpath build from this PR
var wgXPathWindow = { document: {} }; // fake window object used to install wgxpath on
wgxpath.install(wgXPathWindow);
var xml = new DOMParser().parseFromString('<Root><Menu ID="11"></Menu></Root>', "application/xml");
var expression = '/Root';
var wgResult = wgXPathWindow.document.evaluate(expression, xml, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
var nativeResult = xml.evaluate(expression, xml, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
console.log(wgResult); // null
console.log(nativeResult); // <Root> nodeThe above code evaluates the expression using wgxpath expression and the browsers native impl. As you can see the browsers implementation is happy to work without a namespace and no prefix.
Yeah your exactly right, previously I think it would be good to setup some unit tests for some of these things. I would be happy to do it (and even tried for a little) but I am having one heck of a time trying to even run the tests =P. Ill take a look at the unit tests later tonight again. |
|
May be worth double-checking that the predefined |
... Something still doesn't match upJust comment out the
installline vs leaving it to show the difference vs browser implementations.