HADOOP-13810. Add a test to verify that Configuration handles &-encoded characters. Contributed by Steve Loughran

This closes #158

(cherry picked from commit 04014c4c73)
This commit is contained in:
Mingliang Liu 2016-11-14 19:37:50 -08:00
parent efc0e640ed
commit 0feb9bb4a9
1 changed files with 15 additions and 1 deletions

View File

@ -70,6 +70,9 @@ public class TestConfiguration extends TestCase {
IBM_JAVA?"<?xml version=\"1.0\" encoding=\"UTF-8\"?><configuration>": IBM_JAVA?"<?xml version=\"1.0\" encoding=\"UTF-8\"?><configuration>":
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><configuration>"; "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><configuration>";
/** Four apostrophes. */
public static final String ESCAPED = "&apos;&#39;&#0039;&#x27;";
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
@ -314,7 +317,18 @@ public class TestConfiguration extends TestCase {
//two spaces one after "this", one before "contains" //two spaces one after "this", one before "contains"
assertEquals("this contains a comment", conf.get("my.comment")); assertEquals("this contains a comment", conf.get("my.comment"));
} }
public void testEscapedCharactersInValue() throws IOException {
out=new BufferedWriter(new FileWriter(CONFIG));
startConfig();
appendProperty("my.comment", ESCAPED);
endConfig();
Path fileResource = new Path(CONFIG);
conf.addResource(fileResource);
//two spaces one after "this", one before "contains"
assertEquals("''''", conf.get("my.comment"));
}
public void testTrim() throws IOException { public void testTrim() throws IOException {
out=new BufferedWriter(new FileWriter(CONFIG)); out=new BufferedWriter(new FileWriter(CONFIG));
startConfig(); startConfig();