HADOOP-16749. Configuration parsing of CDATA values are blank

Signed-off-by: Jonathan Eagles <jeagles@gmail.com>
(cherry picked from commit c4fb43c942)
This commit is contained in:
Daryn Sharp 2020-01-10 10:31:39 -06:00 committed by Jonathan Eagles
parent 3ba0fd1e50
commit 57cb180267
2 changed files with 38 additions and 0 deletions

View File

@ -3322,6 +3322,7 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
handleStartElement();
break;
case XMLStreamConstants.CHARACTERS:
case XMLStreamConstants.CDATA:
if (parseToken) {
char[] text = reader.getTextCharacters();
token.append(text, reader.getTextStart(), reader.getTextLength());

View File

@ -2553,4 +2553,41 @@ public class TestConfiguration {
// Thread 1
config.get("secondParse");
}
@Test
public void testCDATA() throws IOException {
String xml = new String(
"<configuration>" +
"<property>" +
"<name>cdata</name>" +
"<value><![CDATA[>cdata]]></value>" +
"</property>\n" +
"<property>" +
"<name>cdata-multiple</name>" +
"<value><![CDATA[>cdata1]]> and <![CDATA[>cdata2]]></value>" +
"</property>\n" +
"<property>" +
"<name>cdata-multiline</name>" +
"<value><![CDATA[>cdata\nmultiline<>]]></value>" +
"</property>\n" +
"<property>" +
"<name>cdata-whitespace</name>" +
"<value> prefix <![CDATA[>cdata]]>\nsuffix </value>" +
"</property>\n" +
"</configuration>");
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;
}
}