Skip to content

Commit b27d05a

Browse files
authored
fix path parsing for windows in external_command_args (#162)
1 parent 4497095 commit b27d05a

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

mpvacious/subtitles/observer.lua

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,29 @@ end
3838

3939
local function external_command_args(cur_lines)
4040
local args = {}
41-
for arg in string.gmatch(self.config.autoclip_custom_args, "%S+") do
42-
if arg == '%MPV_PRIMARY%' then
43-
arg = cur_lines.primary
44-
elseif arg == '%MPV_SECONDARY%' then
45-
arg = cur_lines.secondary
41+
42+
-- Append a trailing space to ensure the last argument is captured by the %s+ pattern.
43+
local config_str = self.config.autoclip_custom_args .. " "
44+
45+
-- PATTERN EXPLANATION: [=[(["']?)(.-)%1%s+]=]
46+
-- 1. (["']?) : Capture group 1. Matches an optional single or double quote.
47+
-- 2. (.-) : Capture group 2. Non-greedy match of any character (the actual content).
48+
-- 3. %1 : Back-reference. Ensures the closing quote matches the opening quote.
49+
-- 4. %s+ : Matches one or more trailing whitespace characters to delimit arguments.
50+
local pattern = [=[(["']?)(.-)%1%s+]=]
51+
52+
for _, arg in config_str:gmatch(pattern) do
53+
if arg ~= "" then
54+
if arg == '%MPV_PRIMARY%' then
55+
arg = cur_lines.primary
56+
elseif arg == '%MPV_SECONDARY%' then
57+
arg = cur_lines.secondary
58+
end
59+
60+
table.insert(args, arg)
4661
end
47-
table.insert(args, arg)
4862
end
63+
4964
return args
5065
end
5166

0 commit comments

Comments
 (0)