diff --git a/src/main/java/org/codejive/properties/Properties.java b/src/main/java/org/codejive/properties/Properties.java index 59c3bb7..1d264bf 100644 --- a/src/main/java/org/codejive/properties/Properties.java +++ b/src/main/java/org/codejive/properties/Properties.java @@ -590,7 +590,7 @@ private String escape(String raw, boolean forKey) { replace( raw, "[^\\x{0000}-\\x{00FF}]", - m -> "\\\\u" + Integer.toString(m.group(0).charAt(0), 16)); + m -> "\\\\u" + String.format("%04x", (int)m.group(0).charAt(0))); return raw; } diff --git a/src/test/java/org/codejive/properties/TestProperties.java b/src/test/java/org/codejive/properties/TestProperties.java index 08a6340..dd84047 100644 --- a/src/test/java/org/codejive/properties/TestProperties.java +++ b/src/test/java/org/codejive/properties/TestProperties.java @@ -327,6 +327,16 @@ void testPutNull() throws IOException, URISyntaxException { .isInstanceOf(NullPointerException.class); } + @Test + void testPutUnicode() throws IOException, URISyntaxException { + Properties p = new Properties(); + p.put("test", "الألبانية"); + StringWriter sw = new StringWriter(); + p.store(sw); + assertThat(sw.toString()) + .isEqualTo(readAll(getResource("/test-putunicode.properties"))); + } + @Test void testRemoveFirst() throws IOException, URISyntaxException { Properties p = Properties.loadProperties(getResource("/test.properties")); diff --git a/src/test/resources/test-putunicode.properties b/src/test/resources/test-putunicode.properties new file mode 100644 index 0000000..3978ea1 --- /dev/null +++ b/src/test/resources/test-putunicode.properties @@ -0,0 +1 @@ +test=\u0627\u0644\u0623\u0644\u0628\u0627\u0646\u064a\u0629 \ No newline at end of file