From 23a77050e08a8d57581da43fa8d6cd11ad8eaa0e Mon Sep 17 00:00:00 2001 From: Daryn Sharp Date: Fri, 10 Jan 2020 10:48:45 -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 | 38 +++++++++++++++++++ 2 files changed, 39 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 bb1a02ec200..de9893bdcd9 100644 --- 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 @@ -2925,6 +2925,7 @@ public class Configuration implements Iterable>, 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 f5daf2c886b..d491a52b6c5 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 @@ -63,6 +63,7 @@ import org.apache.log4j.Logger; import org.apache.log4j.spi.LoggingEvent; import org.hamcrest.CoreMatchers; import org.junit.Assert; +import org.junit.Test; import org.mockito.Mockito; import static org.apache.hadoop.util.PlatformName.IBM_JAVA; @@ -2104,4 +2105,41 @@ public class TestConfiguration extends TestCase { TestConfiguration.class.getName() }); } + + @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; + } }