Skip to content

Commit 8497f7e

Browse files
committed
Normalize URL paths: convert /.//p, /..//p, and //p to p
1 parent 3d6dbbb commit 8497f7e

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

url/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,6 +1723,19 @@ impl Url {
17231723
);
17241724
}
17251725
});
1726+
1727+
// To handle cases like <non-spec:/> set pathname to </.//p>
1728+
// For instance, //p should be converted to /.//p here
1729+
if let Some(pos) = self.serialization.rfind("//") {
1730+
let rest = &self.serialization[(pos + 2)..];
1731+
1732+
const PATH_INCREMENT: u32 = 2; // length of "/."
1733+
if rest.len() == 1 {
1734+
self.serialization.replace_range(pos.., &format!("/.//{}", rest));
1735+
self.path_start += PATH_INCREMENT;
1736+
}
1737+
}
1738+
17261739
self.restore_after_path(old_after_path_pos, &after_path);
17271740
}
17281741

url/tests/expected_failures.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,4 @@
4444
<file://monkey/> set pathname to <\\\\>
4545
<file:///unicorn> set pathname to <//\\/>
4646
<file:///unicorn> set pathname to <//monkey/..//>
47-
<non-spec:/> set pathname to </.//p>
48-
<non-spec:/> set pathname to </..//p>
49-
<non-spec:/> set pathname to <//p>
5047
<non-spec:/.//> set pathname to <p>

0 commit comments

Comments
 (0)