-
Notifications
You must be signed in to change notification settings - Fork 74
Description
(This was originally filed as eclipse-m2e/m2e-core#1015, but I was told I need to file it with Eclipse Wild Web Developer.)
Using Eclipse 2022-09, I can add a CDATA section inside a Maven POM (pom.xml) property definition like this:
<properties>
<test.cdata><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<entry key="foo">bar</entry>
</properties>]]></test.cdata>
</properties>The purpose is obvious: I don't want to XML-encode all the XML delimiters in the value.
However when I format the file using Ctrl+Shift+F, Eclipse adds newlines and indents before and after the CDATA section:
<properties>
<test.cdata>
<![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<entry key="foo">bar</entry>
</properties>]]>
</test.cdata>
<properties>This corrupts the data! The whole point of using a CDATA section is that I wanted the exact content specified in a property. Now extra whitespace has been added in the value of the property. (It would have been worse to format inside the CDATA section, but this is still not good.)
I would guess the problem is that the formatting algorithm is treating CDATA sections as if they were XML DOM elements. That is, I understand that if I have this XML:
<foo><bar>…</bar></foo>Then the XML formatter should format it to:
<foo>
<bar>…</bar>
</foo>However CDATA sections are not elements! Their purpose is merely to indicate whether content needs escaping or should be interpreted literally. They do not create a new element nesting context!!! They must be left along entirely; no newlines, whitespace, or anything else should be added, neither inside the CDATA section, before the CDATA section, nor after the CDATA section.