Skip to content

Commit bf4bdd9

Browse files
committed
fix: now properly generating hex escape sequences
Fixes #11
1 parent 9b944cb commit bf4bdd9

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ private String escape(String raw, boolean forKey) {
590590
replace(
591591
raw,
592592
"[^\\x{0000}-\\x{00FF}]",
593-
m -> "\\\\u" + Integer.toString(m.group(0).charAt(0), 16));
593+
m -> "\\\\u" + String.format("%04x", (int)m.group(0).charAt(0)));
594594
return raw;
595595
}
596596

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,16 @@ void testPutNull() throws IOException, URISyntaxException {
327327
.isInstanceOf(NullPointerException.class);
328328
}
329329

330+
@Test
331+
void testPutUnicode() throws IOException, URISyntaxException {
332+
Properties p = new Properties();
333+
p.put("test", "الألبانية");
334+
StringWriter sw = new StringWriter();
335+
p.store(sw);
336+
assertThat(sw.toString())
337+
.isEqualTo(readAll(getResource("/test-putunicode.properties")));
338+
}
339+
330340
@Test
331341
void testRemoveFirst() throws IOException, URISyntaxException {
332342
Properties p = Properties.loadProperties(getResource("/test.properties"));
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test=\u0627\u0644\u0623\u0644\u0628\u0627\u0646\u064a\u0629

0 commit comments

Comments
 (0)