From b4a23e13459b9641de329cf2abb1c8d654cb6638 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Thu, 2 Sep 2021 20:44:15 +0200 Subject: [PATCH] WICG/urlpattern#114 --- src/constructor_parser.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/constructor_parser.rs b/src/constructor_parser.rs index 96511cc..374a734 100644 --- a/src/constructor_parser.rs +++ b/src/constructor_parser.rs @@ -30,6 +30,7 @@ struct ConstructorStringParser<'a> { token_index: usize, token_increment: usize, group_depth: usize, + hostname_ipv6_bracket_depth: usize, protocol_matches_special_scheme: bool, state: ConstructorStringParserState, } @@ -219,6 +220,18 @@ impl<'a> ConstructorStringParser<'a> { self.is_non_special_pattern_char(self.token_index + 2, "/") } } + + // Ref: https://wicg.github.io/urlpattern/#is-an-ipv6-open + #[inline] + fn is_ipv6_open(&self) -> bool { + self.is_non_special_pattern_char(self.token_index, "[") + } + + // Ref: https://wicg.github.io/urlpattern/#is-an-ipv6-close + #[inline] + fn is_ipv6_close(&self) -> bool { + self.is_non_special_pattern_char(self.token_index, "]") + } } // Ref: https://wicg.github.io/urlpattern/#parse-a-constructor-string @@ -246,6 +259,7 @@ pub fn parse_constructor_string( token_index: 0, token_increment: 1, group_depth: 0, + hostname_ipv6_bracket_depth: 0, protocol_matches_special_scheme: false, state: ConstructorStringParserState::Init, }; @@ -342,7 +356,13 @@ pub fn parse_constructor_string( } } ConstructorStringParserState::Hostname => { - if parser.is_port_prefix() { + if parser.is_ipv6_open() { + parser.hostname_ipv6_bracket_depth += 1; + } else if parser.is_ipv6_close() { + parser.hostname_ipv6_bracket_depth -= 1; + } else if parser.is_port_prefix() + && parser.hostname_ipv6_bracket_depth == 0 + { parser.change_state(ConstructorStringParserState::Port, 1); } else if parser.is_pathname_start() { parser.change_state(ConstructorStringParserState::Pathname, 0);