From c4fb43c94259546f2c96b50ceae9cd3adb726166 Mon Sep 17 00:00:00 2001 From: Daryn Sharp Date: Fri, 10 Jan 2020 10:31:39 -0600 Subject: [PATCH] HADOOP-16749. Configuration parsing of CDATA values are blank Signed-off-by: Jonathan Eagles --- .../org/apache/hadoop/conf/Configuration.java | 1 + .../apache/hadoop/conf/TestConfiguration.java | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java index 180bde26574..5119f648036 100755 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java @@ -3350,6 +3350,7 @@ public class Configuration implements Iterable>, handleStartElement(); break; case XMLStreamConstants.CHARACTERS: + case XMLStreamConstants.CDATA: if (parseToken) { char[] text = reader.getTextCharacters(); token.append(text, reader.getTextStart(), reader.getTextLength()); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java index a6adb9f20a3..81c53959478 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java @@ -2553,4 +2553,41 @@ public class TestConfiguration { // Thread 1 config.get("secondParse"); } + + @Test + public void testCDATA() throws IOException { + String xml = new String( + "" + + "" + + "cdata" + + "cdata]]>" + + "\n" + + "" + + "cdata-multiple" + + "cdata1]]> and cdata2]]>" + + "\n" + + "" + + "cdata-multiline" + + "cdata\nmultiline<>]]>" + + "\n" + + "" + + "cdata-whitespace" + + " prefix cdata]]>\nsuffix " + + "\n" + + ""); + Configuration conf = checkCDATA(xml.getBytes()); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + conf.writeXml(os); + checkCDATA(os.toByteArray()); + } + + private static Configuration checkCDATA(byte[] bytes) { + Configuration conf = new Configuration(false); + conf.addResource(new ByteArrayInputStream(bytes)); + assertEquals(">cdata", conf.get("cdata")); + assertEquals(">cdata1 and >cdata2", conf.get("cdata-multiple")); + assertEquals(">cdata\nmultiline<>", conf.get("cdata-multiline")); + assertEquals(" prefix >cdata\nsuffix ", conf.get("cdata-whitespace")); + return conf; + } }