Skip to content

Commit dcf4dd3

Browse files
TheMikeste1mochaaPpre-commit-ci[bot]
authored
fix(pydoclint): escape special characters in file path (#311)
* fix(pydoclint): escape special characters in file path * fixup! fix(pydoclint): escape special characters in file path * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Zephyr Lykos <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 9a5d95c commit dcf4dd3

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lua/null-ls/builtins/diagnostics/pydoclint.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local h = require("null-ls.helpers")
22
local methods = require("null-ls.methods")
3+
local u = require("null-ls.utils")
34

45
local DIAGNOSTICS = methods.internal.DIAGNOSTICS
56

@@ -26,7 +27,7 @@ return h.make_builtin({
2627
end,
2728
multiple_files = false,
2829
on_output = function(line, params)
29-
local path = params.temp_path
30+
local path = u.escape(params.temp_path)
3031
-- rel/path/to/file.py:42: DOC000: Diagnostic message
3132
local pattern = path .. [[:(%d+): (DOC%d+: .*)]]
3233
return h.diagnostics.from_pattern(pattern, { "row", "message" })(line, params)

lua/null-ls/utils/init.lua

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,4 +381,27 @@ M.validate = function(validators)
381381
end
382382
end
383383

384+
--- Make a string literal to match in lua pattern
385+
---@param literal string
386+
---@return string
387+
M.escape = function(literal)
388+
local matches = {
389+
["^"] = "%^",
390+
["$"] = "%$",
391+
["("] = "%(",
392+
[")"] = "%)",
393+
["%"] = "%%",
394+
["."] = "%.",
395+
["["] = "%[",
396+
["]"] = "%]",
397+
["*"] = "%*",
398+
["+"] = "%+",
399+
["-"] = "%-",
400+
["?"] = "%?",
401+
["\0"] = "%z",
402+
}
403+
404+
return (literal:gsub(".", matches))
405+
end
406+
384407
return M

0 commit comments

Comments
 (0)