Skip to content

Windows: Join with different separators #654

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

danielgarzaf
Copy link

This is a weird-edge case for Windows. Some functions can return a string path with Window's separators (i.e. vim.fn.stdpath('data') -> C:\path\to\localappdata). If I were to try and join them like so:

local Path = require("plenary.path")
local data = Path:new(vim.fn.stdpath("data")):joinpath("dir/file.lua")

the resulting data will be a mixed path like C\local\app\data/dir/file.lua.

The proposed solution changes this so that the result is C:\local\app\data\dir\file.lua, and therefore keeps the behavior in line with other modules such as pathlib from python.

NOTE

For the additional test to pass for both Windows and Linux, the additional :gsub("\\", sep) was added.
This means that:

local Path = require("plenary.path")
local data = Path:new("local/app/data"):joinpath("dir\\file.lua")

would result in local/app/data/dir/file.lua even in Linux.

Although I fail to see where this could be an issue, it can be removed.

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.

1 participant