New issue
Advanced search Search tips

Issue 906807 link

Starred by 1 user

Issue metadata

Status: Available
Owner: ----
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Linux , Windows , Mac
Pri: 3
Type: Bug



Sign in to add a comment

XMLSerializer generates unnecessary namespace prefixes

Reported by phrog...@gmail.com, Nov 19

Issue description

UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36

Steps to reproduce the problem:
1. Use DOMParser to create a DOM from XML with a namespace declared on the root element.
2. Use setAttributeNS to create an attribute on a child node using the URI (but not prefix) from the declared namespace prefix.
3. Use XMLSerializer to serialize the DOM.

```
let doc = (new DOMParser).parseFromString('<r xmlns:xx="uri"><b/></r>', 'text/xml');
doc.querySelector('b').setAttributeNS('uri', 'foo', 'bar');
(new XMLSerializer).serializeToString(doc);
```

What is the expected behavior?
The namespaced attribute on the child node uses the namespace prefix declared on the root.

```
<r xmlns:xx="uri"><b xx:foo="bar"/></r>
```

What went wrong?
Chrome generates a new namespace prefix for the existing URI unless setAttribute() is called using the existing namespace prefix.

```
<r xmlns:xx="uri"><b xmlns:ns3839401="uri" ns3839401:foo="bar"/></r>
```

Did this work before? N/A 

Does this work in other browsers? Yes

Chrome version: 70.0.3538.77  Channel: stable
OS Version: 10.0
Flash Version: 

This works correctly on Firefox and Safari.
This test is hosted at http://phrogz.net/tmp/xmlserializertest.html
 
xmlserializertest.html
1.8 KB View Download
Labels: Needs-Triage-M70
Cc: phanindra.mandapaka@chromium.org
Labels: Triaged-ET Target-72 FoundIn-72 M-72 FoundIn-71 FoundIn-70 OS-Linux OS-Mac
Status: Untriaged (was: Unconfirmed)
Able to reproduce the issue on reported chrome version 70.0.3538.77 also on latest chrome 72.0.3615.0 using Mac 10.14.0, Ubuntu 17.10 and Windows 10.  
 
Same behavior is seen on M60(60.0.3112.113) hence considering it as non-regression and marking it as Untriaged.

Thanks! 
Labels: -Pri-2 -M-72 -Target-72 Pri-3
Status: Available (was: Untriaged)
Specification: https://w3c.github.io/DOM-Parsing/#serializing-an-element-s-attributes

Project Member

Comment 4 by bugdroid1@chromium.org, Nov 21

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/7638b860e3ae427a19dec2b35d61366159db28f0

commit 7638b860e3ae427a19dec2b35d61366159db28f0
Author: Kent Tamura <tkent@chromium.org>
Date: Wed Nov 21 13:28:59 2018

Improve readability of MarkupFormatter::AppendAttribute().

- Add comments based on DOM-Parsing specification.
- Introduce |candidate_prefix| variable to follow the specification.

This CL has no behavior changes.

Bug: 906807
Change-Id: I51e7fd9f22fd4f43baac2a85a521af049b5e588c
Reviewed-on: https://chromium-review.googlesource.com/c/1345375
Reviewed-by: Yoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610030}
[modify] https://crrev.com/7638b860e3ae427a19dec2b35d61366159db28f0/third_party/blink/renderer/core/editing/serializers/markup_formatter.cc

Sign in to add a comment