Skip to content

Commit 27f7134

Browse files
committed
Applied the host parsing rules to the setter.
1 parent dd224a3 commit 27f7134

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/lib.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,10 +1569,25 @@ impl Url {
15691569
if host == "" && SchemeType::from(self.scheme()).is_special() {
15701570
return Err(ParseError::EmptyHost);
15711571
}
1572+
let mut host_substr = host;
1573+
// Otherwise, if c is U+003A (:) and the [] flag is unset, then
1574+
if !host.starts_with('[') || !host.ends_with(']') {
1575+
match host.find(':') {
1576+
Some(0) => {
1577+
// If buffer is the empty string, validation error, return failure.
1578+
return Err(ParseError::InvalidDomainCharacter);
1579+
}
1580+
// Let host be the result of host parsing buffer
1581+
Some(colon_index) => {
1582+
host_substr = &host[..colon_index];
1583+
}
1584+
None => {}
1585+
}
1586+
}
15721587
if SchemeType::from(self.scheme()).is_special() {
1573-
self.set_host_internal(Host::parse(host)?, None)
1588+
self.set_host_internal(Host::parse(host_substr)?, None);
15741589
} else {
1575-
self.set_host_internal(Host::parse_opaque(host)?, None)
1590+
self.set_host_internal(Host::parse_opaque(host_substr)?, None);
15761591
}
15771592
} else if self.has_host() {
15781593
if SchemeType::from(self.scheme()).is_special() {

0 commit comments

Comments
 (0)