Skip to content
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

lookupNamespaceURI('xml') #857

Closed
tkent-google opened this issue Apr 10, 2020 · 7 comments · Fixed by #1165 · May be fixed by web-platform-tests/wpt#24371
Closed

lookupNamespaceURI('xml') #857

tkent-google opened this issue Apr 10, 2020 · 7 comments · Fixed by #1165 · May be fixed by web-platform-tests/wpt#24371

Comments

@tkent-google
Copy link
Collaborator

tkent-google commented Apr 10, 2020

Specification: https://dom.spec.whatwg.org/#locate-a-namespace https://dom.spec.whatwg.org/#dom-xpathnsresolver-lookupnamespaceuri https://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathEvaluator-createNSResolver

Chrome, EdgeHTML, and Safari follow the current definition of Node.lookupNamespaceURI() and XPathEvaluator.createNSResolver(). That is to say, Node.lookupNamespacURI() has no special handling for 'xml' prefix, and an object returned by createNSResolver() has it.

On the other hand, Firefox's Node.lookupNamespaceURI('xml') returns the XML namespace if the node is an Element, and Firefox's XPathEvaluator.createNSResolver() just returns the specified node.

I prefer the Firefox behavior because of its simplicity.

Demo code:

<!DOCTYPE html>
<html>
<pre></pre>
<script>
function t(header, node) {
  document.querySelector('pre').textContent += header + ':\traw=' +
      node.lookupNamespaceURI('xml') + '\twrapped=' +
      document.createNSResolver(node).lookupNamespaceURI('xml') + '\n';
}
document.querySelector('pre').textContent += 'Wrapped type: ' +
    document.createNSResolver(document).constructor.name + '\n';

t('Document', new Document());
t('DocumentType', document.doctype);
t('DocumentFragment', document.createDocumentFragment());
t('Attr', document.createAttribute('attr'));
t('Text', document.createTextNode('t'));
t('Element', document.createElement('div'));
</script>
</html>
@tkent-google
Copy link
Collaborator Author

@cdumez or @rniwa What do you think about following the Firefox behavior?

@shvaikalesh
Copy link
Contributor

@tkent-google I believe Chrome and Safari implement "correctly resolving the implicit xml prefix" wording of the spec this way.

Firefox behavior seems more straightforward and, more importantly, is web-compatible. If Chrome will drop special handling of "xml" as well, I will submit WebKit patch when the tests are merged.

@annevk
Copy link
Member

annevk commented Sep 30, 2021

Note that Firefox does this for both xml and xmlns. If we special case xml here we should do the same for xmlns.

@tkent-google
Copy link
Collaborator Author

tkent-google commented Dec 2, 2022

Firefox does this for both xml and xmlns.

Thanks!

So the change will be:

WebKit people, do you have an objection? WebKit can remove NativeXPathNSResolver if we proceed this.

@annevk
Copy link
Member

annevk commented Dec 2, 2022

@tkent-google @shvaikalesh works on WebKit so I'd say this is ready for a PR and tests. (As do I nowadays, but I'll defer to him. 😊)

@cdumez
Copy link

cdumez commented Dec 2, 2022

No objection.

aarongable pushed a commit to chromium/chromium that referenced this issue Dec 2, 2022
If we apply the change of whatwg/dom#857,
createNSResolver() with
 - Attr not owned by an Element,
 - CharacterData not in an Element parent, or
 - Other non-element type nodes
will return incompatible objects.

Bug: whatwg/dom#857
Change-Id: I50434e9b359c50c7c97f3de9a66d3676e76a104d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4075448
Commit-Queue: Joey Arhar <[email protected]>
Reviewed-by: Joey Arhar <[email protected]>
Auto-Submit: Kent Tamura <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1078754}
@tkent-google
Copy link
Collaborator Author

@shvaikalesh works on WebKit so I'd say this is ready for a PR and test

Got it. Thanks!

Google Chrome will collect data about incompatibility of createNSResolver(non-element).lookupNamespaceURI('xml'). I'll check it just in case.

aarongable pushed a commit to chromium/chromium that referenced this issue Dec 6, 2022
The counter introduced by crrev.com/c/4075448 was not precise. We'd
like to count cases where lookupNamespaceURI('xml') will return null.
We don't need to count if 'xml' prefix is not looked up.

Bug: whatwg/dom#857
Change-Id: I4391295ef65f1b28e0ac69c551dc191cc1ed9cc5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4081428
Commit-Queue: Joey Arhar <[email protected]>
Auto-Submit: Kent Tamura <[email protected]>
Reviewed-by: Joey Arhar <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1079620}
aarongable pushed a commit to chromium/chromium that referenced this issue Feb 21, 2023
It counted "xml" lookups for elements incorrectly though we wanted to
count lookups for non-element nodes. This CL fixes the condition, and
switches to a new counter.

Bug: whatwg/dom#857
Change-Id: I467f24e34dce29fcfcc2fcac230af56665d9cc26
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4273811
Reviewed-by: Koji Ishii <[email protected]>
Commit-Queue: Koji Ishii <[email protected]>
Auto-Submit: Kent Tamura <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1107591}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants