File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -8,12 +8,12 @@ local M = {
8
8
9
9
-- get url from line (with http/s)
10
10
function M .handle (mode , line , _ )
11
- local pattern = " (https?://[a-zA-Z0-9_/ %-%.~@\\ +#=?&:]+)"
11
+ local pattern = " (https?://[a-zA-Z%d_/%% %-%.~@\\ +#=?&:]+)"
12
12
local url = helper .find (line , mode , pattern )
13
13
14
14
-- match url without http(s)
15
15
if not url then
16
- pattern = " ([a-zA-Z0-9_ /%-%.~@\\ +#]+%.[a-zA-Z0-9_/% -%.~@\\ +#% =?&:]+)"
16
+ pattern = " ([a-zA-Z%d_ /%-%.~@\\ +#]+%.[a-zA-Z%d_/%%% -%.~@\\ +#=?&:]+)"
17
17
url = helper .find (line , mode , pattern )
18
18
if url then
19
19
return " https://" .. url
Original file line number Diff line number Diff line change @@ -51,4 +51,21 @@ describe("url_parser_does_work", function()
51
51
assert .equals (" https://github.com" , handler .handle (" v" , " // github.com" ))
52
52
assert .equals (" https://github.com" , handler .handle (" v" , ' print("github.com")' ))
53
53
end )
54
+
55
+ it (" encoded urls" , function ()
56
+ assert .equals (
57
+ " https://company.example.com/team-name/repo-name/-/merge_requests/new?merge_request%5Bsource_branch%5D=branch-name" ,
58
+ handler .handle (
59
+ " v" ,
60
+ " https://company.example.com/team-name/repo-name/-/merge_requests/new?merge_request%5Bsource_branch%5D=branch-name"
61
+ )
62
+ )
63
+ assert .equals (
64
+ " http://example.com/?encoded=%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF%21%22%C2%A3%24%25%5E%26%2A%28%29-_%3D%2B%7B%5B%7D%5D%23~%27" ,
65
+ handler .handle (
66
+ " v" ,
67
+ " http://example.com/?encoded=%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF%21%22%C2%A3%24%25%5E%26%2A%28%29-_%3D%2B%7B%5B%7D%5D%23~%27"
68
+ )
69
+ )
70
+ end )
54
71
end )
You can’t perform that action at this time.
0 commit comments