Skip to content

Commit f5cd38e

Browse files
Avoid parsing a path into // when there's no host
This avoids a contradiction where the URL starts out with no host, but gets normalized into a URL where the first part of a path is interpreted as the host. Fixes #397
1 parent a07eac0 commit f5cd38e

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ impl<'a> Parser<'a> {
10451045
*has_host = false; // FIXME account for this in callers
10461046
}
10471047
}
1048-
if ends_with_slash {
1048+
if ends_with_slash && (*has_host || &self.serialization[path_start..] != "/") {
10491049
self.serialization.push('/')
10501050
}
10511051
}

tests/urltestdata.json

+15
Original file line numberDiff line numberDiff line change
@@ -6144,5 +6144,20 @@
61446144
"pathname": "/test",
61456145
"search": "?a",
61466146
"hash": "#bc"
6147+
},
6148+
"Found by fuzzing",
6149+
{
6150+
"input": "a:/a/..//a",
6151+
"base": "about:blank",
6152+
"href": "a:/a",
6153+
"protocol": "a:",
6154+
"username": "",
6155+
"password": "",
6156+
"host": "",
6157+
"hostname": "",
6158+
"port": "",
6159+
"pathname": "/a",
6160+
"search": "",
6161+
"hash": ""
61476162
}
61486163
]

0 commit comments

Comments
 (0)