Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
crowlKats committed Sep 2, 2021
1 parent 4be9fb0 commit b4a23e1
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/constructor_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b4a23e1

Please sign in to comment.