Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes relative IRI resolution when there is no authority #38

Merged
merged 1 commit into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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