diff --git a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/Encode.java b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/Encode.java index 17726659e418b..2d3c74996355d 100644 --- a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/Encode.java +++ b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/Encode.java @@ -389,6 +389,12 @@ protected static String encodeFromArray(String segment, String[] encodingMap, bo result.append(currentChar); continue; } + if (Character.isHighSurrogate(currentChar)) { + String part = segment.substring(i, i + 2); + result.append(URLEncoder.encode(part, StandardCharsets.UTF_8)); + ++i; + continue; + } String encoding = encode(currentChar, encodingMap); if (encoding == null) { result.append(currentChar); diff --git a/independent-projects/resteasy-reactive/common/runtime/src/test/java/org/jboss/resteasy/reactive/common/util/EncodeTest.java b/independent-projects/resteasy-reactive/common/runtime/src/test/java/org/jboss/resteasy/reactive/common/util/EncodeTest.java new file mode 100644 index 0000000000000..9e057ce31126f --- /dev/null +++ b/independent-projects/resteasy-reactive/common/runtime/src/test/java/org/jboss/resteasy/reactive/common/util/EncodeTest.java @@ -0,0 +1,18 @@ +package org.jboss.resteasy.reactive.common.util; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; + +import org.junit.jupiter.api.Test; + +class EncodeTest { + @Test + void encodeEmoji() { + String emoji = "\uD83D\uDE00\uD83D\uDE00\uD83D\uDE00\uD83D\uDE00\uD83D\uDE00\uD83D\uDE00\uD83D\uDE00\uD83D\uDE00"; + String encodedEmoji = URLEncoder.encode(emoji, StandardCharsets.UTF_8); + assertEquals(encodedEmoji, Encode.encodePath(emoji)); + assertEquals(encodedEmoji, Encode.encodeQueryParam(emoji)); + } +}