-
Notifications
You must be signed in to change notification settings - Fork 14
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
Serialization algorithm never preserves attribute prefixes #29
Comments
The following changes would make the algorithm match the expected behavior. I'll try to prepare a PR later.
|
If implemented as specified, the prefix set for an attribute in the DOM would never be preserved during serialization. This change only generates the new prefix if the prefix is either missing (which is not allowed for namespaced attributes), or if it conflicts with another local namespace definition of the prefix for a different namespace. Fixes w3c#29
If implemented as specified, the prefix set for an attribute in the DOM would never be preserved during serialization. This change only generates the new prefix if the prefix is either missing (which is not allowed for namespaced attributes), or if it conflicts with another local namespace definition of the prefix for a different namespace. Fixes w3c#29
@Sebmaster your help again would be appreciated here. Did you do the same thing in https://github.com/jsdom/w3c-xmlserializer as @bwrrp did in slimdon.js? |
Please note that this needs another small change to make sure the selected, newly declared prefix is added to the maps (so it may be reused for similarly namespaced attributes). I'll see if I can update the PR next week to match the slimdom implementation. |
If implemented as specified, the prefix set for an attribute in the DOM would never be preserved during serialization. This change only generates the new prefix if the prefix is either missing (which is not allowed for namespaced attributes), or if it conflicts with another local namespace definition of the prefix for a different namespace. Fixes w3c#29
Ran across this bug as well. Seems like a reference to this issue should be added to the WPT test "Check if an attribute with namespace and no prefix is serialized with the nearest-declared prefix"; an implementation following the spec as written will currently fail this assertion: https://github.com/web-platform-tests/wpt/blame/master/domparsing/XMLSerializer-serializeToString.html#L86 (since it will generate a new prefix instead of reusing one). |
Adding the condition at https://github.com/jsdom/w3c-xmlserializer/blob/master/lib/attributes.js#L92 is the solution by @Sebmaster. That matches the current state of WPT. @bwrrp has a slightly better complicated proposal in bwrrp@97e7bb3 which also preserves the prefix name in the case where the attribute has a prefix but it hasn't (yet) been properly declared. The "'Check if the prefix of an attribute is NOT preserved in a case where neither its prefix nor its namespace URI is not already used." test at https://github.com/web-platform-tests/wpt/blame/master/domparsing/XMLSerializer-serializeToString.html#L126 would have to be updated if this change were made to the spec. Firefox appears to already implement this change, though: > doc = (new DOMParser()).parseFromString("<r xmlns:xx=\"uri\"></r>", "text/xml");
> root = doc.firstChild;
> root.setAttributeNS('uri2', 'p:name', 'value');
> (new XMLSerializer()).serializeToString($doc)
"<r xmlns:xx=\"uri\" p:name=\"value\" xmlns:p=\"uri2\"/>" (The WPT test case states the output should be |
Note also that the "Check if no special handling for XLink namespace unlike HTML serializer." test case in https://github.com/web-platform-tests/wpt/blame/master/domparsing/XMLSerializer-serializeToString.html#L218 also implicitly assumes the "firefox" behavior, not the spec behavior:
The spec currently says the output should be |
Bug: w3c/DOM-Parsing#29 Bug: w3c/DOM-Parsing#38 Bug: w3c/DOM-Parsing#47 Bug: w3c/DOM-Parsing#48 Bug: w3c/DOM-Parsing#50 Bug: w3c/DOM-Parsing#52 Bug: w3c/DOM-Parsing#59 Bug: w3c/DOM-Parsing#71 Change-Id: I76735c4be1d9738c690417207301f737e3a3c9ff
If implemented as described in the specification, the algorithm to serialize an element's attributes (https://w3c.github.io/DOM-Parsing/#serializing-an-element-s-attributes) never preserves the prefix for any namespaced attribute that is not a namespace declaration:
It seems that the candidate prefix generated in step 3.5.1 (marked (*)) is used in neither of the two branches.
Am I correct in assuming that this is not the intended behavior? I would expect a new prefix to be generated only if the existing prefix conflicts with one associated with a different namespace in the local prefix map. This would require an extra check for candidate prefix being null afterwards, as the prefix may need to be redeclared (not regenerated) in that case.
The text was updated successfully, but these errors were encountered: