-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Output polyglot commented CData sections in XML mode
And only if the data does not already contain a (pseudo) CData section. Fixes #2078
- Loading branch information
Showing
5 changed files
with
143 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.jsoup.nodes; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class DataNodeTest { | ||
|
||
@Test | ||
public void xmlOutputScriptWithCData() throws IOException { | ||
DataNode node = new DataNode("//<![CDATA[\nscript && <> data]]>"); | ||
node.parentNode = new Element("script"); | ||
StringBuilder accum = new StringBuilder(); | ||
node.outerHtmlHead(accum, 0, new Document.OutputSettings().syntax(Document.OutputSettings.Syntax.xml)); | ||
assertEquals("//<![CDATA[\nscript && <> data]]>", accum.toString()); | ||
} | ||
|
||
@Test | ||
public void xmlOutputScriptWithoutCData() throws IOException { | ||
DataNode node = new DataNode("script && <> data"); | ||
node.parentNode = new Element("script"); | ||
StringBuilder accum = new StringBuilder(); | ||
node.outerHtmlHead(accum, 0, new Document.OutputSettings().syntax(Document.OutputSettings.Syntax.xml)); | ||
assertEquals("//<![CDATA[\nscript && <> data\n//]]>", accum.toString()); | ||
} | ||
|
||
@Test | ||
public void xmlOutputStyleWithCData() throws IOException { | ||
DataNode node = new DataNode("/*<![CDATA[*/\nstyle && <> data]]>"); | ||
node.parentNode = new Element("style"); | ||
StringBuilder accum = new StringBuilder(); | ||
node.outerHtmlHead(accum, 0, new Document.OutputSettings().syntax(Document.OutputSettings.Syntax.xml)); | ||
assertEquals("/*<![CDATA[*/\nstyle && <> data]]>", accum.toString()); | ||
} | ||
|
||
@Test | ||
public void xmlOutputStyleWithoutCData() throws IOException { | ||
DataNode node = new DataNode("style && <> data"); | ||
node.parentNode = new Element("style"); | ||
StringBuilder accum = new StringBuilder(); | ||
node.outerHtmlHead(accum, 0, new Document.OutputSettings().syntax(Document.OutputSettings.Syntax.xml)); | ||
assertEquals("/*<![CDATA[*/\nstyle && <> data\n/*]]>*/", accum.toString()); | ||
} | ||
|
||
@Test | ||
public void xmlOutputOtherWithCData() throws IOException { | ||
DataNode node = new DataNode("<![CDATA[other && <> data]]>"); | ||
node.parentNode = new Element("other"); | ||
StringBuilder accum = new StringBuilder(); | ||
node.outerHtmlHead(accum, 0, new Document.OutputSettings().syntax(Document.OutputSettings.Syntax.xml)); | ||
assertEquals("<![CDATA[other && <> data]]>", accum.toString()); | ||
} | ||
|
||
@Test | ||
public void xmlOutputOtherWithoutCData() throws IOException { | ||
DataNode node = new DataNode("other && <> data"); | ||
node.parentNode = new Element("other"); | ||
StringBuilder accum = new StringBuilder(); | ||
node.outerHtmlHead(accum, 0, new Document.OutputSettings().syntax(Document.OutputSettings.Syntax.xml)); | ||
assertEquals("<![CDATA[other && <> data]]>", accum.toString()); | ||
} | ||
|
||
@Test | ||
public void xmlOutputOrphanWithoutCData() throws IOException { | ||
DataNode node = new DataNode("other && <> data"); | ||
StringBuilder accum = new StringBuilder(); | ||
node.outerHtmlHead(accum, 0, new Document.OutputSettings().syntax(Document.OutputSettings.Syntax.xml)); | ||
assertEquals("<![CDATA[other && <> data]]>", accum.toString()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters