1.1 --- a/openide.util/src/org/openide/util/EditableProperties.java Wed Aug 12 02:55:48 2009 +0400
1.2 +++ b/openide.util/src/org/openide/util/EditableProperties.java Fri Aug 14 03:04:53 2009 +0400
1.3 @@ -709,8 +709,13 @@
1.4 char ch = input.charAt(x);
1.5 switch(ch) {
1.6 case ' ':
1.7 + if (x == 0 || forKey) {
1.8 + output.append('\\');
1.9 + }
1.10 + output.append(ch);
1.11 + break;
1.12 case '#':
1.13 - if (x == 0 || forKey) {
1.14 + if (x == 0) {
1.15 output.append('\\');
1.16 }
1.17 output.append(ch);
2.1 --- a/openide.util/test/unit/src/org/openide/util/EditablePropertiesTest.java Wed Aug 12 02:55:48 2009 +0400
2.2 +++ b/openide.util/test/unit/src/org/openide/util/EditablePropertiesTest.java Fri Aug 14 03:04:53 2009 +0400
2.3 @@ -55,6 +55,7 @@
2.4 import java.util.HashMap;
2.5 import java.util.Iterator;
2.6 import java.util.Map;
2.7 +import java.util.Properties;
2.8 import org.netbeans.junit.NbTestCase;
2.9
2.10 public class EditablePropertiesTest extends NbTestCase {
2.11 @@ -251,12 +252,12 @@
2.12 String output = getAsString(ep);
2.13 String expected = "a\\ a=a space a"+System.getProperty("line.separator")+
2.14 "b\\u4567=val\\u1234"+System.getProperty("line.separator")+
2.15 - "@!\\#$%^\\\\=!@#$%^&*(){}\\\\"+System.getProperty("line.separator")+
2.16 + "@!#$%^\\\\=!@#$%^&*(){}\\\\"+System.getProperty("line.separator")+
2.17 "d\\nd=d\\nnewline\\nd"+System.getProperty("line.separator")+
2.18 "umlaut=\\u00fc"+System.getProperty("line.separator")+
2.19 "_a\\ a=\\"+System.getProperty("line.separator")+" a space a"+System.getProperty("line.separator")+
2.20 "_b\\u4567=\\"+System.getProperty("line.separator")+" val\\u1234"+System.getProperty("line.separator")+
2.21 - "_@!\\#$%^\\\\=\\"+System.getProperty("line.separator")+" !@#$%^&*\\\\\\"+System.getProperty("line.separator")+
2.22 + "_@!#$%^\\\\=\\"+System.getProperty("line.separator")+" !@#$%^&*\\\\\\"+System.getProperty("line.separator")+
2.23 " (){}\\\\"+System.getProperty("line.separator")+
2.24 "_d\\nd=\\"+System.getProperty("line.separator")+" d\\nnew\\"+System.getProperty("line.separator")+
2.25 " line\\nd\\"+System.getProperty("line.separator")+
2.26 @@ -278,10 +279,17 @@
2.27 }
2.28
2.29 public void testMetaCharacters() throws Exception {
2.30 - testRoundTrip("foo=bar", "v1");
2.31 - testRoundTrip("foo:bar", "v2");
2.32 - testRoundTrip("#foobar", "v3");
2.33 - testRoundTrip(" foo bar ", "v4");
2.34 + testRoundTrip("foo=bar", "v");
2.35 + testRoundTrip("foo:bar", "v");
2.36 + testRoundTrip("#foobar", "v");
2.37 + testRoundTrip("foo#bar", "v");
2.38 + testRoundTrip("foobar#", "v");
2.39 + testRoundTrip("foobar", "#v");
2.40 + testRoundTrip("foobar", "v#");
2.41 + testRoundTrip(" #foo", " #bar");
2.42 + testRoundTrip(" foo bar ", "v");
2.43 + testRoundTrip("foobar", " v ");
2.44 + testRoundTrip("= : # \\\n", "= : # \\\n");
2.45 }
2.46 private void testRoundTrip(String key, String value) throws Exception {
2.47 EditableProperties ep = new EditableProperties(false);
2.48 @@ -291,6 +299,9 @@
2.49 ep = new EditableProperties(false);
2.50 ep.load(new ByteArrayInputStream(baos.toByteArray()));
2.51 assertEquals(baos.toString(), Collections.singletonMap(key, value), ep);
2.52 + Properties p = new Properties();
2.53 + p.load(new ByteArrayInputStream(baos.toByteArray()));
2.54 + assertEquals(baos.toString(), Collections.singletonMap(key, value), p);
2.55 }
2.56
2.57 // test that iterator implementation is OK