Skip to content

Commit

Permalink
Normalize URL paths: convert /.//p, /..//p, and //p to p
Browse files Browse the repository at this point in the history
  • Loading branch information
theskim committed Jun 17, 2024
1 parent 3d6dbbb commit 8497f7e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 13 additions & 0 deletions url/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1723,6 +1723,19 @@ impl Url {
);
}
});

// To handle cases like <non-spec:/> set pathname to </.//p>
// For instance, //p should be converted to /.//p here
if let Some(pos) = self.serialization.rfind("//") {
let rest = &self.serialization[(pos + 2)..];

const PATH_INCREMENT: u32 = 2; // length of "/."
if rest.len() == 1 {
self.serialization.replace_range(pos.., &format!("/.//{}", rest));
self.path_start += PATH_INCREMENT;
}
}

self.restore_after_path(old_after_path_pos, &after_path);
}

Expand Down
3 changes: 0 additions & 3 deletions url/tests/expected_failures.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,4 @@
<file://monkey/> set pathname to <\\\\>
<file:///unicorn> set pathname to <//\\/>
<file:///unicorn> set pathname to <//monkey/..//>
<non-spec:/> set pathname to </.//p>
<non-spec:/> set pathname to </..//p>
<non-spec:/> set pathname to <//p>
<non-spec:/.//> set pathname to <p>

0 comments on commit 8497f7e

Please sign in to comment.