Skip to content

Commit

Permalink
Encode multi char code points correctly in RestEasy Reactive
Browse files Browse the repository at this point in the history
- Fixes quarkusio#10134
- Cherry-picks the commit from RestEasy Classic: resteasy/resteasy@a025820

(cherry picked from commit 054adb6)
  • Loading branch information
gastaldi authored and gsmet committed Jul 20, 2023
1 parent 5b15848 commit 4f44f92
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}

0 comments on commit 4f44f92

Please sign in to comment.