summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-01-11 20:11:59 +0100
committerLinus Groh <mail@linusgroh.de>2022-01-11 21:16:33 +0100
commitf1276144ba36c12cf3750cbf2320e79e52fbeb59 (patch)
tree232d0f205f27052f445354dcfdb75967ef81e9e8
parentde07312cc753d591224cc08ce7c2af5998e1e7c8 (diff)
downloadserenity-f1276144ba36c12cf3750cbf2320e79e52fbeb59.zip
LibJS: Check if input was exhausted after parsing UTC offset fraction
Previously parse_time_zone_numeric_utc_offset_syntax() would return true to indicate success when parsing a string with an invalid number of digits in the fractional seconds part (e.g. 23:59:59.9999999999). We need to check if the lexer has any characters remaining, and return false if that's the case.
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp4
-rw-r--r--Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.js10
2 files changed, 13 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp
index 8372089c69..d6586b1dc8 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp
@@ -230,7 +230,9 @@ static bool parse_time_zone_numeric_utc_offset_syntax(String const& offset_strin
if (!lexer.consume_specific('.') && !lexer.consume_specific(','))
return false;
fraction = lexer.consume_fractional_seconds();
- return fraction.has_value();
+ if (!fraction.has_value())
+ return false;
+ return !lexer.tell_remaining();
}
bool is_valid_time_zone_numeric_utc_offset_syntax(String const& offset_string)
diff --git a/Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.js b/Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.js
index 7dffdef5eb..6d3e53babb 100644
--- a/Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.js
+++ b/Userland/Libraries/LibJS/Tests/builtins/Temporal/TimeZone/TimeZone.js
@@ -10,6 +10,16 @@ describe("errors", () => {
new Temporal.TimeZone("foo");
}).toThrowWithMessage(RangeError, "Invalid time zone name 'foo'");
});
+
+ test("Invalid numeric UTC offset", () => {
+ // FIXME: Error message should probably say '...name or UTC offset ...' :^)
+ expect(() => {
+ new Temporal.TimeZone("0123456");
+ }).toThrowWithMessage(RangeError, "Invalid time zone name '0123456'");
+ expect(() => {
+ new Temporal.TimeZone("23:59:59.9999999999");
+ }).toThrowWithMessage(RangeError, "Invalid time zone name '23:59:59.9999999999'");
+ });
});
describe("normal behavior", () => {