diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2022-04-30 19:29:56 +0300 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-04-30 18:36:10 +0200 |
commit | 7ac9900023476b9b5d1530ad06b77241eb97f7a1 (patch) | |
tree | b790a386cd43274e32aae2e7ea8912cb1d9fec2c /Userland/Libraries | |
parent | 0866a0cd1e81600776d034334950390b3c07a734 (diff) | |
download | serenity-7ac9900023476b9b5d1530ad06b77241eb97f7a1.zip |
LibJS: Reorder parsing for TimeSpecWithOptionalTimeZoneNotAmbiguous
Because `TimeHour TimeZoneNumericUTCOffsetNotAmbiguous[opt]
TimeZoneBracketedAnnotation[opt]` can be a subset of
`TimeHourNotValidMonth TimeZone` we would not exhaust the whole input
in some cases, which would result in an incorrectly thrown exception.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.cpp index cca5fb9370..af32991535 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/ISO8601.cpp @@ -1149,6 +1149,15 @@ bool ISO8601Parser::parse_time_spec_with_optional_time_zone_not_ambiguous() // TimeHour : TimeMinute : TimeSecond TimeFraction[opt] TimeZone[opt] // TimeHour TimeMinute TimeSecondNotValidMonth TimeZone[opt] // TimeHour TimeMinute TimeSecond TimeFraction TimeZone[opt] + // NOTE: Reverse order here because `TimeHour TimeZoneNumericUTCOffsetNotAmbiguous[opt] TimeZoneBracketedAnnotation[opt]` can + // be a subset of `TimeHourNotValidMonth TimeZone`, so we'd not attempt to parse that but may not exhaust the input string. + { + StateTransaction transaction { *this }; + if (parse_time_hour_not_valid_month() && parse_time_zone()) { + transaction.commit(); + return true; + } + } { StateTransaction transaction { *this }; if (parse_time_hour()) { @@ -1196,13 +1205,6 @@ bool ISO8601Parser::parse_time_spec_with_optional_time_zone_not_ambiguous() } { StateTransaction transaction { *this }; - if (parse_time_hour_not_valid_month() && parse_time_zone()) { - transaction.commit(); - return true; - } - } - { - StateTransaction transaction { *this }; if (parse_time_hour_minute_basic_format_not_ambiguous()) { (void)parse_time_zone_bracketed_annotation(); transaction.commit(); |