HADOOP-16749. Configuration parsing of CDATA values are blank

Signed-off-by: Jonathan Eagles <jeagles@gmail.com>
This commit is contained in:
Daryn Sharp 2020-01-10 10:48:45 -06:00 committed by Jonathan Eagles
parent c296e3c0aa
commit 23a77050e0
2 changed files with 39 additions and 0 deletions

View File

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

View File

@ -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(
"<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;
}
}