mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Refine StringUtils#uriDecode and update documentation
Refine the StringUtils#uriDecode method in the following ways: - Use a StringBuilder instead of ByteArrayOutputStream, and only decode %-encoded sequences. - Use HexFormat.fromHexDigits to decode hex sequences. - Decode to a byte array that is only allocated if encoded sequences are encountered. This commit adds another optimization mainly for the use case where there is no encoded sequence, and updates the Javadoc of both StringUtils#uriDecode and UriUtils#decode to match the implementation. Signed-off-by: Patrick Strawderman <pstrawderman@netflix.com> Co-Authored-by: Sebastien Deleuze <sebastien.deleuze@broadcom.com> Closes gh-35253
This commit is contained in:
committed by
Brian Clozel
parent
f3832c7262
commit
24e66b63d1
@@ -107,12 +107,21 @@ class UriUtilsTests {
|
||||
assertThat(UriUtils.decode("T%C5%8Dky%C5%8D", CHARSET)).as("Invalid encoded result").isEqualTo("T\u014dky\u014d");
|
||||
assertThat(UriUtils.decode("/Z%C3%BCrich", CHARSET)).as("Invalid encoded result").isEqualTo("/Z\u00fcrich");
|
||||
assertThat(UriUtils.decode("T\u014dky\u014d", CHARSET)).as("Invalid encoded result").isEqualTo("T\u014dky\u014d");
|
||||
assertThat(UriUtils.decode("%20\u2019", CHARSET)).as("Invalid encoded result").isEqualTo(" \u2019");
|
||||
assertThat(UriUtils.decode("\u015bp\u0159\u00ec\u0144\u0121", CHARSET)).as("Invalid encoded result").isEqualTo("śpřìńġ");
|
||||
assertThat(UriUtils.decode("%20\u015bp\u0159\u00ec\u0144\u0121", CHARSET)).as("Invalid encoded result").isEqualTo(" śpřìńġ");
|
||||
}
|
||||
|
||||
@Test
|
||||
void decodeInvalidSequence() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
UriUtils.decode("foo%2", CHARSET));
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
UriUtils.decode("foo%", CHARSET));
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
UriUtils.decode("%", CHARSET));
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
UriUtils.decode("%zz", CHARSET));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user