Refine UriUtils#decode and StringUtils#uriDecode implementation and documentation#34673
Closed
kilink wants to merge 1 commit into
Closed
Refine UriUtils#decode and StringUtils#uriDecode implementation and documentation#34673kilink wants to merge 1 commit into
UriUtils#decode and StringUtils#uriDecode implementation and documentation#34673kilink wants to merge 1 commit into
Conversation
eec755b to
037a4ec
Compare
nosan
reviewed
Mar 29, 2025
sdeleuze
requested changes
Apr 1, 2025
Contributor
There was a problem hiding this comment.
@kilink Could you please add a Signed-off-by trailer to your commit message as described in https://spring.io/blog/2025/01/06/hello-dco-goodbye-cla-simplifying-contributions-to-spring?
Optimize 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. Signed-off-by: Patrick Strawderman <pstrawderman@netflix.com>
037a4ec to
f3e2a6a
Compare
Contributor
Author
Done. |
UriUtils#decode and StringUtils#uriDecode implementation and documentation
sdeleuze
pushed a commit
to sdeleuze/spring-framework
that referenced
this pull request
Apr 2, 2025
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. Signed-off-by: Patrick Strawderman <pstrawderman@netflix.com> See spring-projectsgh-34673
Contributor
|
Merged with some additional optimizations + a Javadoc update, thanks a lot @kilink. |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Optimize the StringUtils.uriDecode method in the following ways:
Using a StringBuilder and decoding to a temporary byte buffer are inspired by how JDK's URLDecoder works; HexFormat was added in JDK17 and should be more performant than Integer.parseInt as it uses lookup tables.
I initially looked at this as an easy optimization opportunity, but it appears this also resolves the issue raised in #34570; I've added a test case to exercise the problem described in that issue.