Skip to content
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

Only support T as an allowed separator in RFC-3339 dates #3934

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions codegen-server-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ val properties = PropertyRetriever(rootProject, project)
val pluginName = "rust-server-codegen"
val workingDirUnderBuildDir = "smithyprojections/codegen-server-test/"

val checkedInSmithyRuntimeLockfile = rootProject.projectDir.resolve("rust-runtime/Cargo.lock")

dependencies {
implementation(project(":codegen-server"))
implementation("software.amazon.smithy:smithy-aws-protocol-tests:$smithyVersion")
Expand Down Expand Up @@ -106,10 +104,9 @@ val allCodegenTests = "../codegen-core/common-test-models".let { commonModels ->
project.registerGenerateSmithyBuildTask(rootProject, pluginName, allCodegenTests)
project.registerGenerateCargoWorkspaceTask(rootProject, pluginName, allCodegenTests, workingDirUnderBuildDir)
project.registerGenerateCargoConfigTomlTask(layout.buildDirectory.dir(workingDirUnderBuildDir).get().asFile)
project.registerCopyCheckedInCargoLockfileTask(checkedInSmithyRuntimeLockfile, layout.buildDirectory.dir(workingDirUnderBuildDir).get().asFile)

tasks["smithyBuild"].dependsOn("generateSmithyBuild")
tasks["assemble"].finalizedBy("generateCargoWorkspace", "copyCheckedInCargoLockfile", "generateCargoConfigToml")
tasks["assemble"].finalizedBy("generateCargoWorkspace", "generateCargoConfigToml")

project.registerModifyMtimeTask()
project.registerCargoCommandsTasks(layout.buildDirectory.dir(workingDirUnderBuildDir).get().asFile)
Expand Down
2 changes: 1 addition & 1 deletion rust-runtime/aws-smithy-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aws-smithy-types"
version = "1.2.9"
version = "1.2.10"
authors = [
"AWS Rust SDK Team <aws-sdk-rust@amazon.com>",
"Russell Cohen <rcoh@amazon.com>",
Expand Down
43 changes: 43 additions & 0 deletions rust-runtime/aws-smithy-types/src/date_time/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,12 @@ pub(crate) mod rfc3339 {
)
.into());
}
if s.len() > 10 && !matches!(s.as_bytes()[10], b'T' | b't') {
return Err(DateTimeParseErrorKind::Invalid(
"RFC-3339 only allows `T` as a separator for date-time values".into(),
)
.into());
}
let date_time = OffsetDateTime::parse(s, &Rfc3339).map_err(|err| {
DateTimeParseErrorKind::Invalid(format!("invalid RFC-3339 date-time: {}", err).into())
})?;
Expand Down Expand Up @@ -773,6 +779,43 @@ mod tests {
http_date_check_roundtrip(9999999999, 0);
}

#[test]
fn parse_rfc3339_invalid_separator() {
let test_cases = [
("1985-04-12 23:20:50Z", AllowOffsets::OffsetsForbidden),
("1985-04-12x23:20:50Z", AllowOffsets::OffsetsForbidden),
("1985-04-12 23:20:50-02:00", AllowOffsets::OffsetsAllowed),
("1985-04-12a23:20:50-02:00", AllowOffsets::OffsetsAllowed),
];
for (date, offset) in test_cases.into_iter() {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: these into_iter are unnecessary

let dt = rfc3339::parse(date, offset);
assert!(matches!(
dt.unwrap_err(),
DateTimeParseError {
kind: DateTimeParseErrorKind::Invalid(_)
}
));
}
}
#[test]
fn parse_rfc3339_t_separator() {
let test_cases = [
("1985-04-12t23:20:50Z", AllowOffsets::OffsetsForbidden),
("1985-04-12T23:20:50Z", AllowOffsets::OffsetsForbidden),
("1985-04-12t23:20:50-02:00", AllowOffsets::OffsetsAllowed),
("1985-04-12T23:20:50-02:00", AllowOffsets::OffsetsAllowed),
];
for (date, offset) in test_cases.into_iter() {
let dt = rfc3339::parse(date, offset);
assert!(
dt.is_ok(),
"failed to parse date: '{}' with error: {:?}",
date,
dt.err().unwrap()
);
}
}

proptest! {
#![proptest_config(ProptestConfig::with_cases(10000))]

Expand Down
Loading