Skip to content

Commit 581cec3

Browse files
authored
Merge pull request quarkusio#34804 from gastaldi/emoji
Encode multi char code points correctly in RestEasy Reactive
2 parents 11f4ee5 + 054adb6 commit 581cec3

File tree

2 files changed

+24
-0
lines changed
  • independent-projects/resteasy-reactive/common/runtime/src

2 files changed

+24
-0
lines changed

independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/Encode.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,12 @@ protected static String encodeFromArray(String segment, String[] encodingMap, bo
389389
result.append(currentChar);
390390
continue;
391391
}
392+
if (Character.isHighSurrogate(currentChar)) {
393+
String part = segment.substring(i, i + 2);
394+
result.append(URLEncoder.encode(part, StandardCharsets.UTF_8));
395+
++i;
396+
continue;
397+
}
392398
String encoding = encode(currentChar, encodingMap);
393399
if (encoding == null) {
394400
result.append(currentChar);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.jboss.resteasy.reactive.common.util;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import java.net.URLEncoder;
6+
import java.nio.charset.StandardCharsets;
7+
8+
import org.junit.jupiter.api.Test;
9+
10+
class EncodeTest {
11+
@Test
12+
void encodeEmoji() {
13+
String emoji = "\uD83D\uDE00\uD83D\uDE00\uD83D\uDE00\uD83D\uDE00\uD83D\uDE00\uD83D\uDE00\uD83D\uDE00\uD83D\uDE00";
14+
String encodedEmoji = URLEncoder.encode(emoji, StandardCharsets.UTF_8);
15+
assertEquals(encodedEmoji, Encode.encodePath(emoji));
16+
assertEquals(encodedEmoji, Encode.encodeQueryParam(emoji));
17+
}
18+
}

0 commit comments

Comments
 (0)