Skip to content

Commit e233b3d

Browse files
committed
Applied the host parsing rules to the setter.
1 parent a1822f8 commit e233b3d

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
@@ -1625,10 +1625,25 @@ impl Url {
16251625
if host == "" && SchemeType::from(self.scheme()).is_special() {
16261626
return Err(ParseError::EmptyHost);
16271627
}
1628+
let mut host_substr = host;
1629+
// Otherwise, if c is U+003A (:) and the [] flag is unset, then
1630+
if !host.starts_with('[') || !host.ends_with(']') {
1631+
match host.find(':') {
1632+
Some(0) => {
1633+
// If buffer is the empty string, validation error, return failure.
1634+
return Err(ParseError::InvalidDomainCharacter);
1635+
}
1636+
// Let host be the result of host parsing buffer
1637+
Some(colon_index) => {
1638+
host_substr = &host[..colon_index];
1639+
}
1640+
None => {}
1641+
}
1642+
}
16281643
if SchemeType::from(self.scheme()).is_special() {
1629-
self.set_host_internal(Host::parse(host)?, None)
1644+
self.set_host_internal(Host::parse(host_substr)?, None);
16301645
} else {
1631-
self.set_host_internal(Host::parse_opaque(host)?, None)
1646+
self.set_host_internal(Host::parse_opaque(host_substr)?, None);
16321647
}
16331648
} else if self.has_host() {
16341649
if SchemeType::from(self.scheme()).is_special() {

0 commit comments

Comments
 (0)