This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-i18n.git


The following commit(s) were added to refs/heads/master by this push:
     new 396d1de  Add test for duplicate JSON key
396d1de is described below

commit 396d1de7bc0146289deb7aa4884da58f0ed645e6
Author: Konrad Windszus <[email protected]>
AuthorDate: Thu Apr 30 13:52:31 2026 +0200

    Add test for duplicate JSON key
---
 .../sling/i18n/impl/JcrResourceBundleTest.java     | 28 ++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git 
a/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleTest.java 
b/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleTest.java
index 38d9ba5..4c86ed6 100644
--- a/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleTest.java
+++ b/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleTest.java
@@ -29,6 +29,7 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.net.URL;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.LinkedHashMap;
@@ -447,4 +448,31 @@ public class JcrResourceBundleTest {
         }
         assertEquals(MESSAGES_DE.size(), counter);
     }
+
+    @Test
+    public void jsonDictionaryWithDuplicateKey() throws Exception {
+        Node appsI18n = 
getSession().getRootNode().addNode("apps").addNode("i18n", "nt:unstructured");
+        Node deJson = appsI18n.addNode("de.json", "nt:file");
+        deJson.addMixin("mix:language");
+        deJson.setProperty("jcr:language", "de");
+        Node content = deJson.addNode("jcr:content", "nt:resource");
+        content.setProperty("jcr:mimeType", "application/json");
+
+        // manually creating json file, good enough for the test
+        StringBuilder json = new StringBuilder();
+        json.append("{");
+        json.append("\"kitchen\": \"Küche1\",\n");
+        json.append("\"kitchen\": \"Küche2\",\n");
+        json.append("}");
+
+        InputStream stream = new 
ByteArrayInputStream(json.toString().getBytes(StandardCharsets.UTF_8));
+        Binary binary = getSession().getValueFactory().createBinary(stream);
+        content.setProperty("jcr:data", binary);
+        getSession().save();
+
+        // test getString
+        JcrResourceBundle bundle = new JcrResourceBundle(new Locale("de"), 
null, resolver, null, new PathFilter());
+        // last entry wins in case of duplicate keys, test if kitchen2 is 
returned
+        assertEquals("Küche2", bundle.getString("kitchen"));
+    }
 }

Reply via email to