Skip to content

fix: Do not decode + as space - #12432

Merged
Artur- merged 2 commits into
masterfrom
issues/12354_fix_encoding
Nov 29, 2021
Merged

Artur- merged 2 commits into
masterfrom
issues/12354_fix_encoding

Conversation

@caalador

Copy link
Copy Markdown
Contributor

Fix issue with URLDecoder handling
of '+' character.

Fixes #12354

Fix issue with URLDecoder handling
of '+' character.

Fixes #12354
String value = paramAndValue.substring(index + 1);
String value = paramAndValue.substring(index + 1).replace("+", "%2B");
try {
value = URLDecoder.decode(value, "utf-8");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sustainable fix would be to add UrlUtil.decode and UrlUtil.decodeURIComponent that would work the same way as the encode and encodeURIComponent methods and then use the proper one here. It is not only about + but also a number of other characters

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For decode the only cases are:

            case '+':
                sb.append(' ');
            case '%':
                /*
                 * Starting with this instance of %, process all
                 * consecutive substrings of the form %xy. Each
                 * substring %xy will yield a byte. Convert all
                 * consecutive  bytes obtained this way to whatever
                 * character(s) they represent in the provided
                 * encoding.
                 */
                 ...

Everything else is added as is.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also in this specific flow when coming from Location we have the decoded query string from java.net.URI(location).getQuery()

@vaadin-bot

Copy link
Copy Markdown
Collaborator

SonarQube analysis reported 2 issues

  1. MAJOR QueryParameters.java#L137: Define and throw a dedicated exception instead of using a generic one. rule
  2. MINOR QueryParameters.java#L118: Immediately return this expression instead of assigning it to the temporary variable "parsedParams". rule

@Artur-
Artur- merged commit 94766fa into master Nov 29, 2021
@Artur-
Artur- deleted the issues/12354_fix_encoding branch November 29, 2021 10:04
vaadin-bot pushed a commit that referenced this pull request Nov 29, 2021
Fix issue with URLDecoder handling of '+' character.

Fixes #12354
vaadin-bot pushed a commit that referenced this pull request Nov 29, 2021
Fix issue with URLDecoder handling of '+' character.

Fixes #12354
vaadin-bot pushed a commit that referenced this pull request Nov 29, 2021
Fix issue with URLDecoder handling of '+' character.

Fixes #12354
vaadin-bot pushed a commit that referenced this pull request Nov 29, 2021
Fix issue with URLDecoder handling of '+' character.

Fixes #12354
vaadin-bot added a commit that referenced this pull request Nov 29, 2021
Fix issue with URLDecoder handling of '+' character.

Fixes #12354

Co-authored-by: caalador <mikael.grankvist@vaadin.com>
vaadin-bot added a commit that referenced this pull request Nov 29, 2021
Fix issue with URLDecoder handling of '+' character.

Fixes #12354

Co-authored-by: caalador <mikael.grankvist@vaadin.com>
vaadin-bot added a commit that referenced this pull request Nov 29, 2021
Fix issue with URLDecoder handling of '+' character.

Fixes #12354

Co-authored-by: caalador <mikael.grankvist@vaadin.com>
joheriks pushed a commit that referenced this pull request Nov 29, 2021
Fix issue with URLDecoder handling of '+' character.

Fixes #12354

Co-authored-by: caalador <mikael.grankvist@vaadin.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Double decoding of query parameters when creating Location

3 participants