Skip to content

Commit cf305db

Browse files
authored
set_hostname should error when encountering colon ':' (#1060)
1 parent 88826bd commit cf305db

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

url/src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl<'i> Input<'i> {
246246
}
247247

248248
#[inline]
249-
fn starts_with<P: Pattern>(&self, p: P) -> bool {
249+
pub fn starts_with<P: Pattern>(&self, p: P) -> bool {
250250
p.split_prefix(&mut self.clone())
251251
}
252252

url/src/quirks.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,10 @@ pub fn set_hostname(url: &mut Url, new_hostname: &str) -> Result<(), ()> {
212212
return Ok(());
213213
}
214214

215-
if let Ok((host, _remaining)) = Parser::parse_host(input, scheme_type) {
215+
if let Ok((host, remaining)) = Parser::parse_host(input, scheme_type) {
216+
if remaining.starts_with(':') {
217+
return Err(());
218+
};
216219
if let Host::Domain(h) = &host {
217220
if h.is_empty() {
218221
// Empty host on special not file url

url/tests/expected_failures.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
<file:///.//> against <file:////>
3535
<file:.//p>
3636
<file:/.//p>
37-
<http://example.net/path> set hostname to <example.com:8080>
38-
<http://example.net:8080/path> set hostname to <example.com:>
3937
<non-spec:/.//p> set hostname to <h>
4038
<non-spec:/.//p> set hostname to <>
4139
<foo:///some/path> set pathname to <>

0 commit comments

Comments
 (0)