-
Notifications
You must be signed in to change notification settings - Fork 5.5k
http, utility: Allow to optionally decode the parsed param value when parsing query string #11795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
6a7a956
utility: Do URL decoding when parseQueryString
dio 28b4d37
Add one more case
dio 10e849c
Introduce do_percent_decoding flag
dio 0914ff6
Merge remote-tracking branch 'upstream/master'
dio 1ff6b15
Merge remote-tracking branch 'upstream/master'
dio 3c47492
Merge remote-tracking branch 'upstream/master'
dio a098ee0
Introduce Utility::parseAndDecodeQueryString
dio fb30a22
Merge remote-tracking branch 'upstream/master'
dio 9ad3a40
Do decoding only for param values
dio ce9d248
Add flag
dio 451d0c9
Decode by default
dio e570e9c
WIP on defaulting to true
dio 347f3e5
Exclude udpa parsing
dio c41bb5e
Missing param
dio 9da88a1
parseAndDecodeQueryString
dio b37bac6
Merge remote-tracking branch 'upstream/master'
dio 3db0a57
Merge remote-tracking branch 'upstream/master'
dio 3dd1564
Revernt to non decoding for other than admin
dio 581bc5c
Merge remote-tracking branch 'upstream/master'
dio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -264,22 +264,23 @@ std::string Utility::createSslRedirectPath(const RequestHeaderMap& headers) { | |
| return fmt::format("https://{}{}", headers.getHostValue(), headers.getPathValue()); | ||
| } | ||
|
|
||
| Utility::QueryParams Utility::parseQueryString(absl::string_view url) { | ||
| Utility::QueryParams Utility::parseQueryString(absl::string_view url, bool decode_param_value) { | ||
| size_t start = url.find('?'); | ||
| if (start == std::string::npos) { | ||
| QueryParams params; | ||
| return params; | ||
| } | ||
|
|
||
| start++; | ||
| return parseParameters(url, start); | ||
| return parseParameters(url, start, decode_param_value); | ||
| } | ||
|
|
||
| Utility::QueryParams Utility::parseFromBody(absl::string_view body) { | ||
| return parseParameters(body, 0); | ||
| return parseParameters(body, 0, /*decode_param_value=*/true); | ||
| } | ||
|
|
||
| Utility::QueryParams Utility::parseParameters(absl::string_view data, size_t start) { | ||
| Utility::QueryParams Utility::parseParameters(absl::string_view data, size_t start, | ||
| bool decode_param_value) { | ||
| QueryParams params; | ||
|
|
||
| while (start < data.size()) { | ||
|
|
@@ -291,8 +292,9 @@ Utility::QueryParams Utility::parseParameters(absl::string_view data, size_t sta | |
|
|
||
| const size_t equal = param.find('='); | ||
| if (equal != std::string::npos) { | ||
| const auto param_value = StringUtil::subspan(data, start + equal + 1, end); | ||
| params.emplace(StringUtil::subspan(data, start, start + equal), | ||
| StringUtil::subspan(data, start + equal + 1, end)); | ||
| decode_param_value ? PercentEncoding::decode(param_value) : param_value); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should decode param names as well? |
||
| } else { | ||
| params.emplace(StringUtil::subspan(data, start, end), ""); | ||
| } | ||
|
|
||
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
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, but I still think the separate methods was easier to read.