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

fix(prost-types): '+' is not a numeric digit #1104

Merged
merged 1 commit into from
Jul 13, 2024
Merged
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
8 changes: 8 additions & 0 deletions prost-types/src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ fn parse_two_digit_numeric(s: &str) -> Option<(u8, &str)> {
if s.len() < 2 {
return None;
}
if s.starts_with('+') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The digits.parse function will eventually call u8::from_str_radix, which allows to an optional + and then only digits. So checking for the + as the first character is enough to get all the weird cases of parse.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, that seems to be the case!

return None;
}
let (digits, s) = s.split_at(2);
Some((digits.parse().ok()?, s))
}
Expand Down Expand Up @@ -784,6 +787,11 @@ mod tests {
nanos: 0
}),
);
// Leading '+' in two-digit numbers
assert_eq!(
"19+1-+2-+3T+4:+5:+6Z".parse::<Timestamp>(),
Err(crate::TimestampError::ParseFailure),
)
}

#[test]
Expand Down
Loading