Skip to content

Commit 0c115c0

Browse files
committed
fix: we don't escape non-ISO8859-1 chars anymore
Fixes #13
1 parent bf4bdd9 commit 0c115c0

14 files changed

+30
-32
lines changed

src/main/java/org/codejive/properties/Properties.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -579,18 +579,14 @@ private Cursor indexOf(String key) {
579579
}
580580

581581
private String escape(String raw, boolean forKey) {
582+
raw = raw.replace("\\", "\\\\");
582583
raw = raw.replace("\n", "\\n");
583584
raw = raw.replace("\r", "\\r");
584585
raw = raw.replace("\t", "\\t");
585586
raw = raw.replace("\f", "\\f");
586587
if (forKey) {
587588
raw = raw.replace(" ", "\\ ");
588589
}
589-
raw =
590-
replace(
591-
raw,
592-
"[^\\x{0000}-\\x{00FF}]",
593-
m -> "\\\\u" + String.format("%04x", (int)m.group(0).charAt(0)));
594590
return raw;
595591
}
596592

src/test/java/org/codejive/properties/TestProperties.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void testLoad() throws IOException, URISyntaxException {
3030
"everywhere ",
3131
"value",
3232
"one two three",
33-
"\u1234");
33+
"\u1234\u1234");
3434
assertThat(p.rawValues())
3535
.containsExactly(
3636
"simple",
@@ -39,7 +39,7 @@ void testLoad() throws IOException, URISyntaxException {
3939
"everywhere ",
4040
"value",
4141
"one \\\n two \\\n\tthree",
42-
"\\u1234");
42+
"\\u1234\u1234");
4343
}
4444

4545
@Test
@@ -69,7 +69,7 @@ void testGet() throws IOException, URISyntaxException {
6969
assertThat(p.get(" with spaces")).isEqualTo("everywhere ");
7070
assertThat(p.get("altsep")).isEqualTo("value");
7171
assertThat(p.get("multiline")).isEqualTo("one two three");
72-
assertThat(p.get("key.4")).isEqualTo("\u1234");
72+
assertThat(p.get("key.4")).isEqualTo("\u1234\u1234");
7373
}
7474

7575
@Test
@@ -102,7 +102,7 @@ void testGetProperty() throws IOException, URISyntaxException {
102102
assertThat(p.getProperty(" with spaces")).isEqualTo("everywhere ");
103103
assertThat(p.getProperty("altsep")).isEqualTo("");
104104
assertThat(p.getProperty("multiline")).isEqualTo("one two three");
105-
assertThat(p.getProperty("key.4")).isEqualTo("\u1234");
105+
assertThat(p.getProperty("key.4")).isEqualTo("\u1234\u1234");
106106
assertThat(p.getProperty("five")).isEqualTo("5");
107107
assertThat(p.getPropertyComment("five")).containsExactly("# a new comment");
108108
StringWriter sw = new StringWriter();
@@ -119,7 +119,7 @@ void testGetRaw() throws IOException, URISyntaxException {
119119
assertThat(p.getRaw(" with spaces")).isEqualTo("everywhere ");
120120
assertThat(p.getRaw("altsep")).isEqualTo("value");
121121
assertThat(p.getRaw("multiline")).isEqualTo("one \\\n two \\\n\tthree");
122-
assertThat(p.getRaw("key.4")).isEqualTo("\\u1234");
122+
assertThat(p.getRaw("key.4")).isEqualTo("\\u1234\u1234");
123123
}
124124

125125
@Test
@@ -154,7 +154,7 @@ void testPut() throws IOException, URISyntaxException {
154154
p.put(" with spaces", "everywhere ");
155155
p.put("altsep", "value");
156156
p.put("multiline", "one two three");
157-
p.put("key.4", "\u1234");
157+
p.put("key.4", "\u1234\u1234");
158158
assertThat(p).size().isEqualTo(7);
159159
assertThat(p.keySet())
160160
.containsExactly(
@@ -170,7 +170,7 @@ void testPut() throws IOException, URISyntaxException {
170170
"everywhere ",
171171
"value",
172172
"one two three",
173-
"\u1234");
173+
"\u1234\u1234");
174174
assertThat(p.rawValues())
175175
.containsExactly(
176176
"simple",
@@ -179,7 +179,7 @@ void testPut() throws IOException, URISyntaxException {
179179
"everywhere ",
180180
"value",
181181
"one two three",
182-
"\\u1234");
182+
"\u1234\u1234");
183183
StringWriter sw = new StringWriter();
184184
p.store(sw);
185185
assertThat(sw.toString()).isEqualTo(readAll(getResource("/test-put.properties")));
@@ -195,7 +195,7 @@ void testSetProperty() throws IOException, URISyntaxException {
195195
p.setProperty(" with spaces", "everywhere ");
196196
p.setProperty("altsep", "value");
197197
p.setProperty("multiline", "one two three");
198-
p.setProperty("key.4", "\u1234");
198+
p.setProperty("key.4", "\u1234\u1234");
199199
StringWriter sw = new StringWriter();
200200
p.store(sw);
201201
assertThat(sw.toString()).isEqualTo(readAll(getResource("/test-setproperty.properties")));
@@ -210,7 +210,7 @@ void testPutRaw() throws IOException, URISyntaxException {
210210
p.putRaw("\\ with\\ spaces", "everywhere ");
211211
p.putRaw("altsep", "value");
212212
p.putRaw("multiline", "one \\\n two \\\n\tthree");
213-
p.putRaw("key.4", "\\u1234");
213+
p.putRaw("key.4", "\\u1234\u1234");
214214
assertThat(p).size().isEqualTo(7);
215215
assertThat(p.keySet())
216216
.containsExactly(
@@ -226,7 +226,7 @@ void testPutRaw() throws IOException, URISyntaxException {
226226
"everywhere ",
227227
"value",
228228
"one two three",
229-
"\u1234");
229+
"\u1234\u1234");
230230
assertThat(p.rawValues())
231231
.containsExactly(
232232
"simple",
@@ -235,7 +235,7 @@ void testPutRaw() throws IOException, URISyntaxException {
235235
"everywhere ",
236236
"value",
237237
"one \\\n two \\\n\tthree",
238-
"\\u1234");
238+
"\\u1234\u1234");
239239
StringWriter sw = new StringWriter();
240240
p.store(sw);
241241
assertThat(sw.toString()).isEqualTo(readAll(getResource("/test-putraw.properties")));
@@ -330,7 +330,8 @@ void testPutNull() throws IOException, URISyntaxException {
330330
@Test
331331
void testPutUnicode() throws IOException, URISyntaxException {
332332
Properties p = new Properties();
333-
p.put("test", "الألبانية");
333+
p.putRaw("encoded", "\\u0627\\u0644\\u0623\\u0644\\u0628\\u0627\\u0646\\u064a\\u0629");
334+
p.put("text", "\u0627\u0644\u0623\u0644\u0628\u0627\u0646\u064a\u0629");
334335
StringWriter sw = new StringWriter();
335336
p.store(sw);
336337
assertThat(sw.toString())
@@ -431,7 +432,7 @@ public void testInteropLoad() throws IOException, URISyntaxException {
431432
"everywhere ",
432433
"value",
433434
"one two three",
434-
"\u1234");
435+
"\u1234\u1234");
435436
}
436437

437438
@Test
@@ -445,7 +446,7 @@ void testInteropStore() throws IOException, URISyntaxException {
445446
assertThat(sw.toString()).contains("\\ with\\ spaces=everywhere \n");
446447
assertThat(sw.toString()).contains("altsep=value\n");
447448
assertThat(sw.toString()).contains("multiline=one two three\n");
448-
assertThat(sw.toString()).contains("key.4=\u1234\n");
449+
assertThat(sw.toString()).contains("key.4=\u1234\u1234\n");
449450
}
450451

451452
@Test

src/test/resources/test-comment.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ altsep:value
1313
multiline = one \
1414
two \
1515
three
16-
key.4 = \u1234
16+
key.4 = \u1234
1717
# final comment

src/test/resources/test-getproperty.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ three=and escapes\n\t\r\f
44
\ with\ spaces=everywhere
55
altsep=
66
multiline=one two three
7-
key.4=\u1234
7+
key.4=ሴሴ
88
five=5

src/test/resources/test-put.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ three=and escapes\n\t\r\f
44
\ with\ spaces=everywhere
55
altsep=value
66
multiline=one two three
7-
key.4=\u1234
7+
key.4=ሴሴ

src/test/resources/test-putnew.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ altsep:value
1313
multiline = one \
1414
two \
1515
three
16-
key.4 = \u1234
16+
key.4 = \u1234
1717
five=5
1818
# final comment

src/test/resources/test-putraw.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ altsep=value
66
multiline=one \
77
two \
88
three
9-
key.4=\u1234
9+
key.4=\u1234ሴ
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
test=\u0627\u0644\u0623\u0644\u0628\u0627\u0646\u064a\u0629
1+
encoded=\u0627\u0644\u0623\u0644\u0628\u0627\u0646\u064a\u0629
2+
text=الألبانية

src/test/resources/test-removecomment.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ altsep:value
1212
multiline = one \
1313
two \
1414
three
15-
key.4 = \u1234
15+
key.4 = \u1234
1616
# final comment

src/test/resources/test-removefirst.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ altsep:value
1111
multiline = one \
1212
two \
1313
three
14-
key.4 = \u1234
14+
key.4 = \u1234
1515
# final comment

0 commit comments

Comments
 (0)