Skip to content

Add QueryStringDecoder option to leave '+' alone#14850

Merged
normanmaurer merged 3 commits intonetty:4.1from
yawkat:query-plus
Feb 24, 2025
Merged

Add QueryStringDecoder option to leave '+' alone#14850
normanmaurer merged 3 commits intonetty:4.1from
yawkat:query-plus

Conversation

@yawkat
Copy link
Copy Markdown
Contributor

@yawkat yawkat commented Feb 21, 2025

Motivation:

The URI standard RFC 3986 does not specify that query components have their spaces encoded as +. It is implied that the encoding is %20 instead. However, the whatwg HTML standard says explicitly that the query must be encoded using application/x-www-form-urlencoded rules, which does use + for space. This is also what browsers do.

QueryStringDecoder should offer a way to parse either format.

Modification:

  • Modify QueryStringDecoder to use a builder to accommodate the increasing number of flags
  • Add a htmlQueryDecoding flag, enabled by default, to control the + decoding

The default value of htmlQueryDecoding is appropriate for most use cases, I don't think it should be changed even in netty 5.

Also fixed the benchmark harness for Java 21.

Result:

Query strings encoded purely according to the URI spec can be decoded properly.

I measured the performance of the new builder, and it didn't look any different.

Motivation:

The URI standard RFC 3986 does not specify that query components have their spaces encoded as `+`. It is implied that the encoding is `%20` instead. However, the whatwg HTML standard says explicitly that the query must be encoded using `application/x-www-form-urlencoded` rules, which does use `+` for space. This is also what browsers do.

QueryStringDecoder should offer a way to parse either format.

Modification:

- Modify QueryStringDecoder to use a builder to accommodate the increasing number of flags
- Add a `htmlQueryDecoding` flag, enabled by default, to control the `+` decoding

The default value of `htmlQueryDecoding` is appropriate for most use cases, I don't think it should be changed even in netty 5.

Result:

Query strings encoded purely according to the URI spec can be decoded properly.
Comment thread microbench/src/main/java/io/netty/microbench/util/AbstractMicrobenchmark.java Outdated
…obenchmark.java

Co-authored-by: Chris Vest <mr.chrisvest@gmail.com>
@normanmaurer normanmaurer merged commit 7fc6a23 into netty:4.1 Feb 24, 2025
@normanmaurer
Copy link
Copy Markdown
Member

@yawkat thanks a lot!

normanmaurer pushed a commit that referenced this pull request Feb 24, 2025
Motivation:

The URI standard RFC 3986 does not specify that query components have
their spaces encoded as `+`. It is implied that the encoding is `%20`
instead. However, the whatwg HTML standard says explicitly that the
query must be encoded using `application/x-www-form-urlencoded` rules,
which does use `+` for space. This is also what browsers do.

QueryStringDecoder should offer a way to parse either format.

Modification:

- Modify QueryStringDecoder to use a builder to accommodate the
increasing number of flags
- Add a `htmlQueryDecoding` flag, enabled by default, to control the `+`
decoding

The default value of `htmlQueryDecoding` is appropriate for most use
cases, I don't think it should be changed even in netty 5.

Also fixed the benchmark harness for Java 21.

Result:

Query strings encoded purely according to the URI spec can be decoded
properly.

I measured the performance of the new builder, and it didn't look any
different.

---------

Co-authored-by: Chris Vest <mr.chrisvest@gmail.com>
@normanmaurer normanmaurer added this to the 4.1.119.Final milestone Feb 24, 2025
normanmaurer added a commit that referenced this pull request Feb 24, 2025
Motivation:

The URI standard RFC 3986 does not specify that query components have
their spaces encoded as `+`. It is implied that the encoding is `%20`
instead. However, the whatwg HTML standard says explicitly that the
query must be encoded using `application/x-www-form-urlencoded` rules,
which does use `+` for space. This is also what browsers do.

QueryStringDecoder should offer a way to parse either format.

Modification:

- Modify QueryStringDecoder to use a builder to accommodate the
increasing number of flags
- Add a `htmlQueryDecoding` flag, enabled by default, to control the `+`
decoding

The default value of `htmlQueryDecoding` is appropriate for most use
cases, I don't think it should be changed even in netty 5.

Also fixed the benchmark harness for Java 21.

Result:

Query strings encoded purely according to the URI spec can be decoded
properly.

I measured the performance of the new builder, and it didn't look any
different.

Co-authored-by: Jonas Konrad <me@yawk.at>
Co-authored-by: Chris Vest <mr.chrisvest@gmail.com>
normanmaurer added a commit that referenced this pull request Feb 24, 2025
Motivation:

The URI standard RFC 3986 does not specify that query components have
their spaces encoded as `+`. It is implied that the encoding is `%20`
instead. However, the whatwg HTML standard says explicitly that the
query must be encoded using `application/x-www-form-urlencoded` rules,
which does use `+` for space. This is also what browsers do.

QueryStringDecoder should offer a way to parse either format.

Modification:

- Modify QueryStringDecoder to use a builder to accommodate the
increasing number of flags
- Add a `htmlQueryDecoding` flag, enabled by default, to control the `+`
decoding

The default value of `htmlQueryDecoding` is appropriate for most use
cases, I don't think it should be changed even in netty 5.

Also fixed the benchmark harness for Java 21.

Result:

Query strings encoded purely according to the URI spec can be decoded
properly.

I measured the performance of the new builder, and it didn't look any
different.

Co-authored-by: Jonas Konrad <me@yawk.at>
Co-authored-by: Chris Vest <mr.chrisvest@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants