Skip to content

Commit 134a9b3

Browse files
authored
fix: handle errors in git utils convert_octal_to_utf8 (#817)
1 parent 0a2e518 commit 134a9b3

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lua/neo-tree/git/utils.lua

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,18 @@ M.get_repository_root = function(path, callback)
4848
end
4949
end
5050

51+
local convert_octal_char = function(octal)
52+
return string.char(tonumber(octal, 8))
53+
end
54+
5155
M.octal_to_utf8 = function(text)
5256
-- git uses octal encoding for utf-8 filepaths, convert octal back to utf-8
53-
text = text:gsub("\\([0-7][0-7][0-7])", function(octal)
54-
return string.char(tonumber(octal, 8))
55-
end)
56-
return text
57+
local converted, success = pcall(string.gsub, text, "\\([0-7][0-7][0-7])", convert_octal_char)
58+
if success then
59+
return converted
60+
else
61+
return text
62+
end
5763
end
5864

5965
return M

0 commit comments

Comments
 (0)