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

kwin pushed a commit to branch feature/test-for-duplicate-key-in-json
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-i18n.git

commit af4af3aca98173a72bb1c416b5be99de83cb30c4
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     | 27 ++++++++++++++++++++++
 1 file changed, 27 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..8e1a679 100644
--- a/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleTest.java
+++ b/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleTest.java
@@ -447,4 +447,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());
+        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