[PATCH 2 of 2] JSON is not restricted to ASCII

Wald Commits scm-commit at wald.intevation.org
Thu Nov 2 17:42:47 CET 2023


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1698943270 -3600
#      Thu Nov 02 17:41:10 2023 +0100
# Branch 3.2.x
# Node ID efbdaf72aafeb35940e65703af8c7de71d5a5cc5
# Parent  0135bf3bd92b203ce2aa0a601fcf4f1de4f9ac9c
JSON is not restricted to ASCII

diff -r 0135bf3bd92b -r efbdaf72aafe artifacts-common/src/main/java/org/dive4elements/artifacts/common/utils/JSON.java
--- a/artifacts-common/src/main/java/org/dive4elements/artifacts/common/utils/JSON.java	Thu Nov 02 15:09:22 2023 +0100
+++ b/artifacts-common/src/main/java/org/dive4elements/artifacts/common/utils/JSON.java	Thu Nov 02 17:41:10 2023 +0100
@@ -78,18 +78,7 @@
                 case '\n': sb.append("\\n"); break;
                 case '\b': sb.append("\\b"); break;
                 case '\f': sb.append("\\f"); break;
-                default:
-                    if (c >= 128) {
-                        sb.append("\\u");
-                        String hex = Integer.toHexString((int)c);
-                        for (int j = 4-hex.length(); j > 0; --j) {
-                            sb.append('0');
-                        }
-                        sb.append(hex);
-                    }
-                    else {
-                        sb.append(c);
-                    }
+                default: sb.append(c);
             }
         }
 
diff -r 0135bf3bd92b -r efbdaf72aafe artifacts-common/src/test/java/org/dive4elements/artifacts/common/utils/JSONTest.java
--- a/artifacts-common/src/test/java/org/dive4elements/artifacts/common/utils/JSONTest.java	Thu Nov 02 15:09:22 2023 +0100
+++ b/artifacts-common/src/test/java/org/dive4elements/artifacts/common/utils/JSONTest.java	Thu Nov 02 17:41:10 2023 +0100
@@ -26,4 +26,12 @@
             + "}",
             JSON.toJSONString(json));
     }
+
+    @Test
+    public void toNonASCIIJSONString() {
+        final Map<String, Object> json = new HashMap<>();
+        json.put("täst", "täst");
+
+        assertEquals("{\"täst\":\"täst\"}", JSON.toJSONString(json));
+    }
 }


More information about the Dive4Elements-commits mailing list