Skip to content

Commit

Permalink
Fix query replacement for non-spaced queries (Hammerspoon#272)
Browse files Browse the repository at this point in the history
`string.gsub` returns two values: the string with substitutions and the number of substitutions made

If doing the nested `gsub`, these two return values will be passed into the outer `gsub`, which accepts an optional fourth parameter specifying how many substitutions should be made. So the number of substitutions in the inner `gsub` determines the number of substitutions in the outer `gsub`: When the query doesn't contain a blank, that number of substitutions in the inner `gsub` is `0` and the outer `gsub` won't replace anything, leaving '${query}' in the `url`.
  • Loading branch information
thomasjachmann authored and eraserhd committed Jul 11, 2024
1 parent ed1a0f2 commit 3ab26c1
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Source/Seal.spoon/seal_useractions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ function obj.completionCallback(row)
obj.actions[row.actionname].fn(row.arg)
elseif obj.actions[row.actionname].url then
row.arg = hs.http.encodeForQuery(row.arg)
local url = string.gsub(obj.actions[row.actionname].url, '${query}', row.arg:gsub("%%", "%%%%"))
local query = row.arg:gsub("%%", "%%%%")
local url = string.gsub(obj.actions[row.actionname].url, '${query}', query)
obj.openURL(url)
end
end
Expand Down

0 comments on commit 3ab26c1

Please sign in to comment.