Skip to content

Conversation

@sxyazi
Copy link
Owner

@sxyazi sxyazi commented Nov 24, 2025

Prepare for #611

With #3034, Url gained support for virtual filesystem namespaces, which means a scheme can appear in the URL now, so it can be used like this:

local url = Url("sftp://my-server//path/to/file"):strip_prefix("sftp://my-server//path")
print(url)  -- Url("/to/file")

The value returned here is actually a path that does not include the scheme (sftp://my-server/), so returning it as a Url no longer makes sense:

  • Url("/to/file") denotes a local file whose path is /to/file.
  • But it's a remote file /to/file in the my-server namespace

That ambiguity can create potential security risks, for example, passing it to an API like fs.remove() could end up deleting a local file when the intention was to delete a remote one.

By introducing Path and restricting its usage, for example, fs.remove() accepts only Url and not Path, so that users must explicitly construct a Url from a Path before operating on it, which reduces misuse-driven security risks and enforces type safety:

local path = Url("sftp://my-server//path/to/file"):strip_prefix("sftp://my-server//path")
print(path)  -- Path("/to/file")

local url = Url("sftp://my-server/" .. path)
fs.remove("file", path)  -- Errors out to avoid removing the local file `/to/file` by mistake
fs.remove("file", url)  -- Removes remote file `sftp://my-server//to/file`, which is intentional

⚠️ Breaking change

Url's strip_prefix() method now returns a newly introduced Path type instead of the original Url.

Path exposes all of Url's API except for the scheme. Documentation is available at https://yazi-rs.github.io/docs/next/plugins/types#path

@sxyazi sxyazi merged commit e5bcdf5 into main Nov 24, 2025
6 checks passed
@sxyazi sxyazi deleted the pr-27d9f0d6 branch November 24, 2025 06:10
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

Successfully merging this pull request may close these issues.

2 participants