Skip to content

Commit ec2f2d0

Browse files
authored
Ensure parsing throws with unknown critical annotations (#63)
1 parent 2b4cbb2 commit ec2f2d0

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

src/components/date.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,4 +847,20 @@ mod tests {
847847
assert!(Date::<()>::from_str(s).is_err())
848848
}
849849
}
850+
851+
// test262/test/built-ins/Temporal/Calendar/prototype/day/argument-string-critical-unknown-annotation.js
852+
#[test]
853+
fn argument_string_critical_unknown_annotation() {
854+
const INVALID_STRINGS: [&str; 6] = [
855+
"1970-01-01[!foo=bar]",
856+
"1970-01-01T00:00[!foo=bar]",
857+
"1970-01-01T00:00[UTC][!foo=bar]",
858+
"1970-01-01T00:00[u-ca=iso8601][!foo=bar]",
859+
"1970-01-01T00:00[UTC][!foo=bar][u-ca=iso8601]",
860+
"1970-01-01T00:00[foo=bar][!_foo-bar0=Dont-Ignore-This-99999999999]",
861+
];
862+
for s in INVALID_STRINGS {
863+
assert!(Date::<()>::from_str(s).is_err())
864+
}
865+
}
850866
}

src/parsers.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ fn parse_ixdtf(source: &str, variant: ParseVariant) -> TemporalResult<IxdtfParse
3838
}
3939
None => first_calendar = Some(annotation),
4040
}
41+
return None;
4142
}
4243

43-
// Ignore all invalid annotations
44-
None
44+
// Make the parser handle any unknown annotation.
45+
Some(annotation)
4546
});
4647

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

6162
// Validate that the DateRecord exists.
62-
if result.date.is_none() {
63+
if record.date.is_none() {
6364
return Err(
6465
TemporalError::syntax().with_message("DateTime strings must contain a Date value.")
6566
);
6667
}
6768

68-
result.calendar = first_calendar.map(|v| v.value);
69+
record.calendar = first_calendar.map(|v| v.value);
6970

70-
Ok(result)
71+
Ok(record)
7172
}
7273

7374
/// A utility function for parsing a `DateTime` string

0 commit comments

Comments
 (0)