Skip to content

Commit

Permalink
Fixes relative IRI resolution when there is no authority
Browse files Browse the repository at this point in the history
  • Loading branch information
Tpt committed Oct 19, 2024
1 parent d57d747 commit 8470490
Show file tree
Hide file tree
Showing 3 changed files with 377 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Changed

- Fixes relativize on hierarchical paths without authority and starting slash Thomas Tanon 31 minutes ago
- Fixes relativize on hierarchical paths without authority and starting slash.

## [0.2.5] - 2024-10-03

Expand Down
27 changes: 14 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1451,10 +1451,6 @@ impl<'a, O: OutputBuffer, const UNCHECKED: bool> IriParser<'a, O, UNCHECKED> {
self.output_positions.authority_end = base.positions.authority_end;
self.output_positions.path_end = base.positions.path_end;
self.remove_last_segment();
if self.output.len() > base.positions.scheme_end {
// We have some path or authority, we keep a base '/'
self.output.push('/');
}
self.parse_relative_path()
}
}
Expand Down Expand Up @@ -1646,12 +1642,10 @@ impl<'a, O: OutputBuffer, const UNCHECKED: bool> IriParser<'a, O, UNCHECKED> {
match c {
None | Some('/') | Some('?') | Some('#') => {
if self.output.as_str().ends_with("/..") {
self.output.truncate(self.output.len() - 3);
self.remove_last_segment();
self.remove_last_segment();
self.output.push('/');
} else if self.output.as_str().ends_with("/.") {
self.remove_last_segment();
self.output.push('/');
self.output.truncate(self.output.len() - 1);
} else if c == Some('/') {
self.output.push('/');
}
Expand Down Expand Up @@ -1704,11 +1698,18 @@ impl<'a, O: OutputBuffer, const UNCHECKED: bool> IriParser<'a, O, UNCHECKED> {
}

fn remove_last_segment(&mut self) {
let last_slash_position = self.output.as_str()[self.output_positions.authority_end..]
.rfind('/')
.unwrap_or(0);
self.output
.truncate(last_slash_position + self.output_positions.authority_end)
if let Some(last_slash_position) =
self.output.as_str()[self.output_positions.authority_end..].rfind('/')
{
self.output
.truncate(last_slash_position + self.output_positions.authority_end);
self.output.push('/');
} else {
self.output.truncate(self.output_positions.authority_end);
if self.output_positions.authority_end > self.output_positions.scheme_end {
self.output.push('/');
}
}
}

fn read_url_codepoint_or_echar(
Expand Down
Loading

0 comments on commit 8470490

Please sign in to comment.