-
Notifications
You must be signed in to change notification settings - Fork 196
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
Upgrade Smithy to 1.16.1 #1053
Merged
Merged
Upgrade Smithy to 1.16.1 #1053
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d8b33c9
Upgrade Smithy to 1.16.1
jdisanti 50b469e
Update changelog
jdisanti 41a721b
Merge remote-tracking branch 'upstream/main' into jdisanti-upgrade-to…
jdisanti 98bf201
Fix ktlint
jdisanti d8712e6
Fix clippy
jdisanti 02df022
Fix header quoting issues
jdisanti d5b30de
Add fuzz test for `read_many_from_str`
jdisanti be45634
Merge remote-tracking branch 'upstream/main' into jdisanti-upgrade-to…
jdisanti d9f55cf
Fix codegen integration tests
jdisanti ad08f55
Incorporate feedback
jdisanti 230b37c
Merge remote-tracking branch 'upstream/main' into jdisanti-upgrade-to…
jdisanti 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 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 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 |
---|---|---|
|
@@ -171,6 +171,13 @@ mod parse_multi_header { | |
use super::ParseError; | ||
use std::borrow::Cow; | ||
|
||
fn trim(s: Cow<'_, str>) -> Cow<'_, str> { | ||
match s { | ||
Cow::Owned(s) => Cow::Owned(s.trim().into()), | ||
Cow::Borrowed(s) => Cow::Borrowed(s.trim()), | ||
} | ||
} | ||
|
||
/// Reads a single value out of the given input, and returns a tuple containing | ||
/// the parsed value and the remainder of the slice that can be used to parse | ||
/// more values. | ||
|
@@ -180,7 +187,10 @@ mod parse_multi_header { | |
match byte { | ||
b' ' | b'\t' => { /* skip whitespace */ } | ||
b'"' => return read_quoted_value(¤t_slice[1..]), | ||
_ => return read_unquoted_value(current_slice), | ||
_ => { | ||
let (value, rest) = read_unquoted_value(current_slice)?; | ||
return Ok((trim(value), rest)); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -193,7 +203,7 @@ mod parse_multi_header { | |
let (first, next) = input.split_at(next_delim); | ||
let first = std::str::from_utf8(first) | ||
.map_err(|_| ParseError::new_with_message("header was not valid utf8"))?; | ||
Ok((Cow::Borrowed(first), then_delim(next).unwrap())) | ||
Ok((Cow::Borrowed(first), then_comma(next).unwrap())) | ||
} | ||
|
||
/// Reads a header value that is surrounded by quotation marks and may have escaped | ||
|
@@ -209,7 +219,10 @@ mod parse_multi_header { | |
if inner.contains("\\\"") { | ||
inner = Cow::Owned(inner.replace("\\\"", "\"")); | ||
} | ||
let rest = then_delim(&input[(index + 1)..])?; | ||
if inner.contains("\\\\") { | ||
inner = Cow::Owned(inner.replace("\\\\", "\\")); | ||
} | ||
let rest = then_comma(&input[(index + 1)..])?; | ||
return Ok((inner, rest)); | ||
} | ||
_ => {} | ||
|
@@ -220,7 +233,7 @@ mod parse_multi_header { | |
)) | ||
} | ||
|
||
fn then_delim(s: &[u8]) -> Result<&[u8], ParseError> { | ||
fn then_comma(s: &[u8]) -> Result<&[u8], ParseError> { | ||
if s.is_empty() { | ||
Ok(s) | ||
} else if s.starts_with(b",") { | ||
|
@@ -237,14 +250,22 @@ fn read_one<'a, T>( | |
f: &impl Fn(&str) -> Result<T, ParseError>, | ||
) -> Result<(T, &'a [u8]), ParseError> { | ||
let (value, rest) = parse_multi_header::read_value(s)?; | ||
Ok((f(value.trim())?, rest)) | ||
Ok((f(&value)?, rest)) | ||
} | ||
|
||
/// Conditionally quotes and escapes a header value if the header value contains a comma or quote. | ||
pub fn quote_header_value<'a>(value: impl Into<Cow<'a, str>>) -> Cow<'a, str> { | ||
let value = value.into(); | ||
if value.contains('"') || value.contains(',') { | ||
Cow::Owned(format!("\"{}\"", value.replace('"', "\\\""))) | ||
if value.trim().len() != value.len() | ||
|| value.contains('"') | ||
|| value.contains(',') | ||
|| value.contains('(') | ||
|| value.contains(')') | ||
{ | ||
Cow::Owned(format!( | ||
"\"{}\"", | ||
value.replace('\\', "\\\\").replace('"', "\\\"") | ||
)) | ||
} else { | ||
value | ||
} | ||
|
@@ -314,50 +335,31 @@ mod test { | |
.header("MultipleEpochSeconds", "1234.5678,9012.3456") | ||
.body(()) | ||
.unwrap(); | ||
let read = |name: &str, format: Format| { | ||
many_dates(test_request.headers().get_all(name).iter(), format) | ||
}; | ||
let read_valid = |name: &str, format: Format| read(name, format).expect("valid"); | ||
assert_eq!( | ||
many_dates( | ||
test_request.headers().get_all("Empty").iter(), | ||
Format::DateTime | ||
) | ||
.expect("valid"), | ||
read_valid("Empty", Format::DateTime), | ||
Vec::<DateTime>::new() | ||
); | ||
assert_eq!( | ||
many_dates( | ||
test_request.headers().get_all("SingleHttpDate").iter(), | ||
Format::HttpDate | ||
) | ||
.expect("valid"), | ||
read_valid("SingleHttpDate", Format::HttpDate), | ||
vec![DateTime::from_secs_and_nanos(1445412480, 0)] | ||
); | ||
assert_eq!( | ||
many_dates( | ||
test_request.headers().get_all("MultipleHttpDates").iter(), | ||
Format::HttpDate | ||
) | ||
.expect("valid"), | ||
read_valid("MultipleHttpDates", Format::HttpDate), | ||
vec![ | ||
DateTime::from_secs_and_nanos(1445412480, 0), | ||
DateTime::from_secs_and_nanos(1445498880, 0) | ||
] | ||
); | ||
assert_eq!( | ||
many_dates( | ||
test_request.headers().get_all("SingleEpochSeconds").iter(), | ||
Format::EpochSeconds | ||
) | ||
.expect("valid"), | ||
read_valid("SingleEpochSeconds", Format::EpochSeconds), | ||
vec![DateTime::from_secs_and_nanos(1234, 567_800_000)] | ||
); | ||
assert_eq!( | ||
many_dates( | ||
test_request | ||
.headers() | ||
.get_all("MultipleEpochSeconds") | ||
.iter(), | ||
Format::EpochSeconds | ||
) | ||
.expect("valid"), | ||
read_valid("MultipleEpochSeconds", Format::EpochSeconds), | ||
vec![ | ||
DateTime::from_secs_and_nanos(1234, 567_800_000), | ||
DateTime::from_secs_and_nanos(9012, 345_600_000) | ||
|
@@ -369,41 +371,39 @@ mod test { | |
fn read_many_strings() { | ||
let test_request = http::Request::builder() | ||
.header("Empty", "") | ||
.header("Foo", "foo") | ||
.header("Foo", " foo") | ||
.header("FooInQuotes", "\" foo\"") | ||
.header("CommaInQuotes", "\"foo,bar\",baz") | ||
.header("QuoteInQuotes", "\"foo\\\",bar\",\"\\\"asdf\\\"\",baz") | ||
.header( | ||
"QuoteInQuotesWithSpaces", | ||
"\"foo\\\",bar\", \"\\\"asdf\\\"\", baz", | ||
) | ||
.header("JunkFollowingQuotes", "\"\\\"asdf\\\"\"baz") | ||
.header("EmptyQuotes", "\"\",baz") | ||
.header("EscapedSlashesInQuotes", "foo, \"(foo\\\\bar)\"") | ||
.body(()) | ||
.unwrap(); | ||
let read = | ||
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 probably also hit trailing whitespace |
||
|name: &str| read_many_from_str::<String>(test_request.headers().get_all(name).iter()); | ||
let read_valid = |name: &str| read(name).expect("valid"); | ||
assert_eq!(read_valid("Empty"), Vec::<String>::new()); | ||
assert_eq!(read_valid("Foo"), vec!["foo"]); | ||
assert_eq!(read_valid("FooInQuotes"), vec![" foo"]); | ||
assert_eq!(read_valid("CommaInQuotes"), vec!["foo,bar", "baz"]); | ||
assert_eq!( | ||
read_many_from_str::<String>(test_request.headers().get_all("Empty").iter()) | ||
.expect("valid"), | ||
Vec::<String>::new(), | ||
); | ||
assert_eq!( | ||
read_many_from_str::<String>(test_request.headers().get_all("Foo").iter()) | ||
.expect("valid"), | ||
vec!["foo"] | ||
); | ||
assert_eq!( | ||
read_many_from_str::<String>(test_request.headers().get_all("CommaInQuotes").iter()) | ||
.expect("valid"), | ||
vec!["foo,bar", "baz"] | ||
read_valid("QuoteInQuotes"), | ||
vec!["foo\",bar", "\"asdf\"", "baz"] | ||
); | ||
assert_eq!( | ||
read_many_from_str::<String>(test_request.headers().get_all("QuoteInQuotes").iter()) | ||
.expect("valid"), | ||
read_valid("QuoteInQuotesWithSpaces"), | ||
vec!["foo\",bar", "\"asdf\"", "baz"] | ||
); | ||
assert!(read_many_from_str::<String>( | ||
test_request.headers().get_all("JunkFollowingQuotes").iter() | ||
) | ||
.is_err()); | ||
assert!(read("JunkFollowingQuotes").is_err()); | ||
assert_eq!(read_valid("EmptyQuotes"), vec!["", "baz"]); | ||
assert_eq!( | ||
read_many_from_str::<String>(test_request.headers().get_all("EmptyQuotes").iter()) | ||
.expect("valid"), | ||
vec!["", "baz"] | ||
read_valid("EscapedSlashesInQuotes"), | ||
vec!["foo", "(foo\\bar)"] | ||
); | ||
} | ||
|
||
|
@@ -501,9 +501,13 @@ mod test { | |
fn test_quote_header_value() { | ||
assert_eq!("", "e_header_value("")); | ||
assert_eq!("foo", "e_header_value("foo")); | ||
assert_eq!("\" foo\"", "e_header_value(" foo")); | ||
assert_eq!("foo bar", "e_header_value("foo bar")); | ||
assert_eq!("\"foo,bar\"", "e_header_value("foo,bar")); | ||
assert_eq!("\",\"", "e_header_value(",")); | ||
assert_eq!("\"\\\"foo\\\"\"", "e_header_value("\"foo\"")); | ||
assert_eq!("\"\\\"f\\\\oo\\\"\"", "e_header_value("\"f\\oo\"")); | ||
assert_eq!("\"(\"", "e_header_value("(")); | ||
assert_eq!("\")\"", "e_header_value(")")); | ||
} | ||
} |
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.
could factor out
fn replace(cow, pat, pat) -> cow