Skip to content

Commit 7aa0ac2

Browse files
committed
lpeg_patterns/uri: Fix bug where percent encoded host characters would not get case-normalised
Removed 'host_char' pattern that was not in RFC
1 parent ece14fa commit 7aa0ac2

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lpeg_patterns/uri.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,11 @@ end
5959

6060
local IP_literal = P"[" * ( IPv6addrz + IPvFuture ) * P"]"
6161
local IP_host = ( IP_literal + IPv4address ) / tostring
62-
local host_char = unreserved / string.lower + _M.pct_encoded + _M.sub_delims
63-
local reg_name = Cs ( host_char^1 ) + Cc ( nil )
62+
local reg_name = Cs((
63+
unreserved / string.lower
64+
+ _M.pct_encoded / function(s) return s:sub(1,1) == "%" and s or string.lower(s) end
65+
+ _M.sub_delims
66+
)^1) + Cc(nil)
6467
_M.host = IP_host + reg_name
6568

6669
_M.port = DIGIT^0 / tonumber -- 3.2.3

spec/uri_spec.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ describe("URI", function()
8282
it("Should match localhost", function()
8383
assert.same({host="localhost"}, ref:match "//localhost")
8484
assert.same({host="localhost"}, ref:match "//LOCALHOST")
85+
assert.same({host="localhost"}, ref:match "//l%4FcAlH%6fSt")
8586
assert.same({host="localhost", port=8000}, ref:match "//localhost:8000")
8687
assert.same({scheme="http", host="localhost", port=8000}, uri:match "http://localhost:8000")
8788
end)

0 commit comments

Comments
 (0)