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

Poping a path segment removes slash separator #912

Open
1 task done
dsherret opened this issue Mar 8, 2024 · 2 comments
Open
1 task done

Poping a path segment removes slash separator #912

dsherret opened this issue Mar 8, 2024 · 2 comments

Comments

@dsherret
Copy link
Contributor

dsherret commented Mar 8, 2024

  • Note that this crate implements the URL Standard not RFC 1738 or RFC 3986

Describe the bug

Given the following code:

fn pop_last_segment(mut url: Url) -> Url {
  if let Ok(mut segments) = url.path_segments_mut() {
    segments.pop();
  }
  url
}

I get the following input and output:

IN:  file:///bar/deno.json
OUT: file:///bar

I would have expected the following output instead with a trailing slash so that it remains a directory:

file:///bar/
@Scripter17
Copy link

As I understand it, a URL path is basically a Vec<String> joined by and prefixed with "/", so this is the correct behavior

I assume something along the lines of if let Some(_) = segments.pop() {segments.push("");} should give what you want

@dsherret
Copy link
Contributor Author

dsherret commented Mar 8, 2024

I ended up working around it, but it seems strange that this would be desired behaviour. For example instead of:

file:///some/path/to/file.js (file)
file:///some/path/to (file)
file:///some/path (file)
file:///some (file)

I would expect:

file:///some/path/to/file.js (file)
file:///some/path/to/ (dir)
file:///some/path/ (dir)
file:///some/ (dir)

Because when you're poping from a file url, you're going to the parent directory rather than a file in the grandparent directory with the same name as the parent directory.

Edit: Sorry, I accidentally hit some keyboard shortcut and closed the issue.

@dsherret dsherret closed this as completed Mar 8, 2024
@dsherret dsherret reopened this Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants