Skip to content

Commit

Permalink
feat: Accept verbatim host matches alongside patterns
Browse files Browse the repository at this point in the history
The documentation mostly makes it seem like verbatim host matches are
accepted while under the hood, gitlinker actually uses string.match().
This works most of the time, but breaks, for example, when a hostname
contains a `-`.

Both verbtim matches and pattern matches are useful features - support
them both properly by first attempting a verbatim match and then a
pattern match.
  • Loading branch information
Rahix committed Jan 28, 2022
1 parent e83ebb3 commit 0443a35
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lua/gitlinker/hosts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,14 @@ end

--- Gets a matching callback for a given host
--
-- @param target_host the host to get the matching callback from
-- @param target_host the host to get the matching callback from.
-- this can be either a verbatim match or a lua string.match pattern.
--
-- @returns the host's callback
function M.get_matching_callback(target_host)
local matching_callback
for host, callback in pairs(M.callbacks) do
if target_host:match(host) then
if target_host == host or target_host:match(host) then
matching_callback = callback
break
end
Expand Down

0 comments on commit 0443a35

Please sign in to comment.