fix(windows): treat both backslash and frontslash as path separators (#336)

This commit is contained in:
Steven Arcangeli 2024-04-23 20:21:56 -07:00
parent 96f0983e75
commit 3b3a6b23a1
2 changed files with 16 additions and 11 deletions

View file

@ -4,6 +4,7 @@ local cache = require("oil.cache")
local columns = require("oil.columns")
local config = require("oil.config")
local constants = require("oil.constants")
local fs = require("oil.fs")
local lsp_helpers = require("oil.lsp.helpers")
local oil = require("oil")
local parser = require("oil.mutator.parser")
@ -99,7 +100,8 @@ M.create_actions_from_diffs = function(all_diffs)
table.insert(by_id, diff)
else
-- Parse nested files like foo/bar/baz
local pieces = vim.split(diff.name, "/")
local path_sep = fs.is_windows and "[/\\]" or "/"
local pieces = vim.split(diff.name, path_sep)
local url = parent_url:gsub("/$", "")
for i, v in ipairs(pieces) do
local is_last = i == #pieces

View file

@ -210,23 +210,26 @@ M.parse = function(bufnr)
end
local parsed_entry = result.data
local entry = result.entry
if not parsed_entry.name or parsed_entry.name:match("/") or not entry then
local message
if not parsed_entry.name then
message = "No filename found"
elseif not entry then
message = "Could not find existing entry (was the ID changed?)"
else
message = "Filename cannot contain '/'"
end
local err_message
if not parsed_entry.name then
err_message = "No filename found"
elseif not entry then
err_message = "Could not find existing entry (was the ID changed?)"
elseif parsed_entry.name:match("/") or parsed_entry.name:match(fs.sep) then
err_message = "Filename cannot contain path separator"
end
if err_message then
table.insert(errors, {
message = message,
message = err_message,
lnum = i - 1,
end_lnum = i,
col = 0,
})
goto continue
end
assert(entry)
check_dupe(parsed_entry.name, i)
local meta = entry[FIELD_META]
if original_entries[parsed_entry.name] == parsed_entry.id then