Skip to content
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
16 changes: 16 additions & 0 deletions src/components/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -847,4 +847,20 @@ mod tests {
assert!(Date::<()>::from_str(s).is_err())
}
}

// test262/test/built-ins/Temporal/Calendar/prototype/day/argument-string-critical-unknown-annotation.js
#[test]
fn argument_string_critical_unknown_annotation() {
const INVALID_STRINGS: [&str; 6] = [
"1970-01-01[!foo=bar]",
"1970-01-01T00:00[!foo=bar]",
"1970-01-01T00:00[UTC][!foo=bar]",
"1970-01-01T00:00[u-ca=iso8601][!foo=bar]",
"1970-01-01T00:00[UTC][!foo=bar][u-ca=iso8601]",
"1970-01-01T00:00[foo=bar][!_foo-bar0=Dont-Ignore-This-99999999999]",
];
for s in INVALID_STRINGS {
assert!(Date::<()>::from_str(s).is_err())
}
}
}
13 changes: 7 additions & 6 deletions src/parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ fn parse_ixdtf(source: &str, variant: ParseVariant) -> TemporalResult<IxdtfParse
}
None => first_calendar = Some(annotation),
}
return None;
}

// Ignore all invalid annotations
None
// Make the parser handle any unknown annotation.
Some(annotation)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah shoot! Nice catch.

});

let mut result = match variant {
let mut record = match variant {
ParseVariant::YearMonth => parser.parse_year_month_with_annotation_handler(handler),
ParseVariant::MonthDay => parser.parse_month_day_with_annotation_handler(handler),
ParseVariant::DateTime => parser.parse_with_annotation_handler(handler),
Expand All @@ -59,15 +60,15 @@ fn parse_ixdtf(source: &str, variant: ParseVariant) -> TemporalResult<IxdtfParse
}

// Validate that the DateRecord exists.
if result.date.is_none() {
if record.date.is_none() {
return Err(
TemporalError::syntax().with_message("DateTime strings must contain a Date value.")
);
}

result.calendar = first_calendar.map(|v| v.value);
record.calendar = first_calendar.map(|v| v.value);

Ok(result)
Ok(record)
}

/// A utility function for parsing a `DateTime` string
Expand Down