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; + } }