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

restrict month day numbers in date formats #96

Merged
merged 1 commit into from
Dec 30, 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
27 changes: 23 additions & 4 deletions parser/src/json/formats.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
pub fn lookup_format(name: &str) -> Option<&str> {
let r = match name {
"date-time" => {
r"^(?P<date>[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12][0-9]|3[01]))[tT](?P<time>(?:[01][0-9]|2[0-3]):[0-5][0-9]:(?:[0-5][0-9]|60)(?P<time_fraction>\.[0-9]+)?(?P<time_zone>[zZ]|[+-](?:[01][0-9]|2[0-3]):[0-5][0-9]))$"
}
"date-time" => concat!(
r"^(?P<date>",
r"[0-9]{4}-(?:",
r"(?:0[13578]|1[02])-(?:0[1-9]|[12][0-9]|3[01])|", // 31-day months
r"(?:0[469]|11)-(?:0[1-9]|[12][0-9]|30)|", // 30-day months
r"(?:02)-(?:0[1-9]|1[0-9]|2[0-9])", // February up to 29 days
r"))",
r"[tT](?P<time>",
r"(?:[01][0-9]|2[0-3]):[0-5][0-9]:", // Hours, Minutes
r"(?:[0-5][0-9]|60)", // Seconds (including leap second 60)
r"(?P<time_fraction>\.[0-9]+)?", // Optional fractional seconds
r"(?P<time_zone>",
r"[zZ]|[+-](?:[01][0-9]|2[0-3]):[0-5][0-9]", // Time zone
r")",
r")$"
),
"time" => {
r"^(?:[01][0-9]|2[0-3]):[0-5][0-9]:(?:[0-5][0-9]|60)(?P<time_fraction>\.[0-9]+)?(?P<time_zone>[zZ]|[+-](?:[01][0-9]|2[0-3]):[0-5][0-9])$"
}
"date" => r"^[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12][0-9]|3[01])$",
"date" => concat!(
r"^(?:",
r"(?:[0-9]{4}-(?:0[13578]|1[02])-(?:0[1-9]|[12][0-9]|3[01]))|", // Months with 31 days
r"(?:[0-9]{4}-(?:0[469]|11)-(?:0[1-9]|[12][0-9]|30))|", // Months with 30 days
r"(?:[0-9]{4}-02-(?:0[1-9]|1[0-9]|2[0-9]))", // February with up to 29 days
r")$"
),
"duration" => {
r"^P(?:(?P<dur_date>(?:(?P<dur_year>[0-9]+Y(?:[0-9]+M(?:[0-9]+D)?)?)|(?P<dur_month>[0-9]+M(?:[0-9]+D)?)|(?P<dur_day>[0-9]+D))(?:T(?:(?P<dur_hour>[0-9]+H(?:[0-9]+M(?:[0-9]+S)?)?)|(?P<dur_minute>[0-9]+M(?:[0-9]+S)?)|(?P<dur_second>[0-9]+S)))?)|(?P<dur_time>T(?:(?P<dur_hour2>[0-9]+H(?:[0-9]+M(?:[0-9]+S)?)?)|(?P<dur_minute2>[0-9]+M(?:[0-9]+S)?)|(?P<dur_second2>[0-9]+S)))|(?P<dur_week>[0-9]+W))$"
}
Expand Down
Loading