Merged
Conversation
mildbyte
approved these changes
Sep 26, 2022
| log = "0.4" | ||
| moka = { version = "0.9.3", default_features = false, features = ["future", "atomic64", "quanta"] } | ||
| object_store = "0.5.0" | ||
| percent-encoding = "2.2.0" |
Contributor
There was a problem hiding this comment.
Nice, it also looks like we're already importing this as a transitive dependency (so it's not going to result in us pulling in extra code)
~/seafowl $ cargo tree | grep percent
│ │ │ │ ├── percent-encoding v2.2.0
│ │ │ │ │ ├── percent-encoding v2.2.0
│ │ │ │ │ │ │ └── percent-encoding v2.2.0
│ │ │ │ │ │ ├── percent-encoding v2.2.0
│ │ ├── percent-encoding v2.2.0
│ └── percent-encoding v2.2.0
│ ├── percent-encoding v2.2.0
│ │ ├── percent-encoding v2.2.0
Comment on lines
+223
to
+229
| let decoded_query = percent_decode_str(&raw_query).decode_utf8(); | ||
|
|
||
| if decoded_query.is_err() { | ||
| return Err(ApiError::QueryDecodeError); | ||
| } | ||
|
|
||
| let hash_str = str_to_hex_hash(&decoded_query.as_ref().unwrap()); |
Contributor
There was a problem hiding this comment.
Instead of using unwrap(), you should use the ? operator to bail out with an Err value and safely extract the Ok value otherwise:
Suggested change
| let decoded_query = percent_decode_str(&raw_query).decode_utf8(); | |
| if decoded_query.is_err() { | |
| return Err(ApiError::QueryDecodeError); | |
| } | |
| let hash_str = str_to_hex_hash(&decoded_query.as_ref().unwrap()); | |
| let decoded_query = percent_decode_str(&raw_query).decode_utf8().map_err(|_| ApiError::QueryDecodeError)?; | |
| let hash_str = str_to_hex_hash(decoded_query); |
(decoded_query should have the type String going ahead, so you don't need unwrap() which will panic at runtime if it encounters an Error value)
786c6e8 to
808aeeb
Compare
headers cannot contain special characters such as newlines (as is described in GH issue #104). The solution is to percent-encode (aka: encodeURIComponent()) the query string. Encoding is not mandatory, some characters like the space are HTTP header-safe, these characters can be sent both as they are or percent encoded (e.g. %20 for space).
3be0e3d to
5d2c6f3
Compare
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.
headers cannot contain special characters such as newlines (as is described in GH issue #104). The solution is to percent-encode (aka: encodeURIComponent()) the query string. Encoding is not mandatory, some characters like the space are HTTP header-safe, these characters can be sent both as they are or percent encoded (e.g. %20 for space).