From f62ce1a42fda096c838184f32dea1acee7126ea2 Mon Sep 17 00:00:00 2001 From: Jackson Ludwig <42984254+jacksonludwig@users.noreply.github.com> Date: Thu, 14 May 2026 20:23:39 -0400 Subject: [PATCH] fix(difftool): handle filenames containing spaces #39740 Problem: Using the `DiffTool` plugin (e.g. through `nvim -d ...` or `:DiffTool ` fails if a space is in one of the paths. This occurs because the `diff` wraps the paths with quotes (`'`) if space characters are present, which the line diff regex fails to parse. Solution: Update regex to handle quoted paths by matching the string within the quotes, if it exists. (cherry picked from commit 1e09b020e57f203636bdf1199eb1bc8bb2d364a4) --- runtime/pack/dist/opt/nvim.difftool/lua/difftool.lua | 2 +- test/functional/plugin/difftool_spec.lua | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/runtime/pack/dist/opt/nvim.difftool/lua/difftool.lua b/runtime/pack/dist/opt/nvim.difftool/lua/difftool.lua index 1601fafea3..7fb6e70b6b 100644 --- a/runtime/pack/dist/opt/nvim.difftool/lua/difftool.lua +++ b/runtime/pack/dist/opt/nvim.difftool/lua/difftool.lua @@ -123,7 +123,7 @@ local function diff_dirs_diffr(left_dir, right_dir, opt) local qf_entries = {} for _, line in ipairs(lines) do - local modified_left, modified_right = line:match('^Files (.+) and (.+) differ$') + local modified_left, modified_right = line:match("^Files '?(.-)'? and '?(.-)'? differ$") if modified_left and modified_right then local left_exists = vim.fn.filereadable(modified_left) == 1 local right_exists = vim.fn.filereadable(modified_right) == 1 diff --git a/test/functional/plugin/difftool_spec.lua b/test/functional/plugin/difftool_spec.lua index 567376bda3..c1ab1f92f9 100644 --- a/test/functional/plugin/difftool_spec.lua +++ b/test/functional/plugin/difftool_spec.lua @@ -15,8 +15,10 @@ setup(function() n.mkdir_p(testdir_right) t.write_file(testdir_left .. pathsep .. 'file1.txt', 'hello') t.write_file(testdir_left .. pathsep .. 'file2.txt', 'foo') + t.write_file(testdir_left .. pathsep .. 'file4 with space.txt', 'hello') t.write_file(testdir_right .. pathsep .. 'file1.txt', 'hello world') -- modified t.write_file(testdir_right .. pathsep .. 'file3.txt', 'bar') -- added + t.write_file(testdir_right .. pathsep .. 'file4 with space.txt', 'hello world') -- modified end) teardown(function() @@ -42,10 +44,12 @@ describe('nvim.difftool', function() -- file1.txt as modified (M) -- file2.txt as deleted (D) -- file3.txt as added (A) + -- file4 with space.txt as modified (M) eq({ { text = 'M', rel = 'file1.txt' }, { text = 'D', rel = 'file2.txt' }, { text = 'A', rel = 'file3.txt' }, + { text = 'M', rel = 'file4 with space.txt' }, }, entries) end) @@ -83,6 +87,7 @@ describe('nvim.difftool', function() eq({ { text = 'M', rel = 'file1.txt' }, { text = 'A', rel = 'file3.txt' }, + { text = 'M', rel = 'file4 with space.txt' }, }, entries) end) @@ -144,6 +149,7 @@ describe('nvim.difftool', function() { text = 'M', rel = 'file1.txt' }, { text = 'D', rel = 'file2.txt' }, { text = 'A', rel = 'file3.txt' }, + { text = 'M', rel = 'file4 with space.txt' }, }, entries) end) end)