Skip to content

Commit e3b4b7f

Browse files
authored
Reject non-iso calendar in YearMonth::from_str and MonthDay::from_str (#211)
This PR adds one missed step on parsing `YearMonth::from_str` and `MonthDay::from_str` which needs to reject any non `iso8601` calendar if it is parsed.
1 parent a7f4825 commit e3b4b7f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/builtins/core/month_day.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ impl FromStr for PlainMonthDay {
126126
.transpose()?
127127
.unwrap_or_default();
128128

129+
// ParseISODateTime
130+
// Step 4.a.ii.3
131+
// If goal is TemporalMonthDayString or TemporalYearMonthString, calendar is
132+
// not empty, and the ASCII-lowercase of calendar is not "iso8601", throw a
133+
// RangeError exception.
134+
if !calendar.is_iso() {
135+
return Err(TemporalError::range().with_message("non-ISO calendar not supported."));
136+
}
137+
129138
let date = record.date;
130139

131140
let date = date.temporal_unwrap()?;

src/builtins/core/year_month.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,15 @@ impl FromStr for PlainYearMonth {
262262
.transpose()?
263263
.unwrap_or_default();
264264

265+
// ParseISODateTime
266+
// Step 4.a.ii.3
267+
// If goal is TemporalMonthDayString or TemporalYearMonthString, calendar is
268+
// not empty, and the ASCII-lowercase of calendar is not "iso8601", throw a
269+
// RangeError exception.
270+
if !calendar.is_iso() {
271+
return Err(TemporalError::range().with_message("non-ISO calendar not supported."));
272+
}
273+
265274
let date = record.date.temporal_unwrap()?;
266275

267276
// The below steps are from `ToTemporalYearMonth`
@@ -316,6 +325,7 @@ mod tests {
316325
"+275760-10",
317326
"+275760-10-01",
318327
"+275760-10-01T00:00",
328+
"1976-11[u-ca=hebrew]",
319329
];
320330

321331
for invalid_case in invalid_strings {

0 commit comments

Comments
 (0)