Skip to content

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