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

coheigea pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/main by this push:
     new 93677953a8f Encode supplementary characters correctly in 
URIParserUtil.escapeChars (#3787)
93677953a8f is described below

commit 93677953a8fc98037510b446b452c34b4f8d408e
Author: Colm O hEigeartaigh <[email protected]>
AuthorDate: Thu Nov 26 11:29:58 2026 +0000

    Encode supplementary characters correctly in URIParserUtil.escapeChars 
(#3787)
---
 .../main/java/org/apache/cxf/common/util/URIParserUtil.java  | 12 +++++++-----
 .../java/org/apache/cxf/common/util/URIParserUtilTest.java   | 10 +++++++++-
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/core/src/main/java/org/apache/cxf/common/util/URIParserUtil.java 
b/core/src/main/java/org/apache/cxf/common/util/URIParserUtil.java
index 462896f038c..63d2db13a3e 100644
--- a/core/src/main/java/org/apache/cxf/common/util/URIParserUtil.java
+++ b/core/src/main/java/org/apache/cxf/common/util/URIParserUtil.java
@@ -67,17 +67,19 @@ public final class URIParserUtil {
     public static String escapeChars(String s) {
         StringBuilder sb = new StringBuilder(s.length());
 
-        for (int x = 0; x < s.length(); x++) {
-            char ch = s.charAt(x);
-            if (isExcluded(ch)) {
-                byte[] bytes = 
Character.toString(ch).getBytes(StandardCharsets.UTF_8);
+        for (int x = 0; x < s.length();) {
+            int cp = s.codePointAt(x);
+            int len = Character.charCount(cp);
+            if (len > 1 || isExcluded((char)cp)) {
+                byte[] bytes = s.substring(x, x + 
len).getBytes(StandardCharsets.UTF_8);
                 for (byte b : bytes) {
                     sb.append('%');
                     StringUtils.byteToHex(b, sb);
                 }
             } else {
-                sb.append(ch);
+                sb.append((char)cp);
             }
+            x += len;
         }
         return sb.toString();
     }
diff --git 
a/core/src/test/java/org/apache/cxf/common/util/URIParserUtilTest.java 
b/core/src/test/java/org/apache/cxf/common/util/URIParserUtilTest.java
index d6a9fb190f7..e94bb683010 100644
--- a/core/src/test/java/org/apache/cxf/common/util/URIParserUtilTest.java
+++ b/core/src/test/java/org/apache/cxf/common/util/URIParserUtilTest.java
@@ -124,4 +124,12 @@ public class URIParserUtilTest {
         assertEquals(orig, URLDecoder.decode(s, 
StandardCharsets.UTF_8.name()));
     }
 
-}
\ No newline at end of file
+    @Test
+    public void testEscapeCharsSupplementaryCharacter() throws Exception {
+        String orig = "/foo" + new String(Character.toChars(0x1F600)) + ".txt";
+        String s = URIParserUtil.escapeChars(orig);
+        assertEquals("/foo%f0%9f%98%80.txt", s);
+        assertEquals(orig, URLDecoder.decode(s, 
StandardCharsets.UTF_8.name()));
+    }
+
+}

Reply via email to