File tree Expand file tree Collapse file tree 2 files changed +14
-5
lines changed
Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -56,14 +56,14 @@ M.build_pattern = function(pattern)
5656 pattern = " //" .. pattern
5757 end
5858
59+ -- escape dots and dashes in pattern
60+ pattern = pattern :gsub (" ([%.%-])" , " %%%1" )
61+
5962 -- an asterisk for the port means allow all ports
6063 if string.find (pattern , " [:]+%*$" ) ~= nil then
6164 pattern = pattern :gsub (" [:]+%*$" , " [:]+[0-9]+" )
6265 end
6366
64- -- escape dots in pattern
65- pattern = pattern :gsub (" %." , " %%." )
66-
6767 -- append end character
6868 pattern = pattern .. " $"
6969 return pattern
Original file line number Diff line number Diff line change @@ -96,6 +96,11 @@ function test_build_pattern_7()
9696 luaunit .assertEquals (result , " http://test%.com[:]+[0-9]+$" )
9797end
9898
99+ function test_build_pattern_8 ()
100+ local result = cors .build_pattern (" te-st.com" )
101+ luaunit .assertEquals (result , " //te%-st%.com$" )
102+ end
103+
99104function test_get_allowed_origin_case_1 ()
100105 local result = cors .get_allowed_origin (" http://test.com" , {" http://test.com" })
101106 luaunit .assertEquals (result , " http://test.com" )
@@ -151,11 +156,15 @@ function test_get_allowed_origin_case_11()
151156 luaunit .assertEquals (result , " *" )
152157end
153158
154-
155159function test_get_allowed_origin_case_12 ()
156160 local result = cors .get_allowed_origin (" http://test.com:8080" , {" http://test.com:*" })
157161 luaunit .assertEquals (result , " http://test.com:8080" )
158162end
159163
164+ function test_get_allowed_origin_case_13 ()
165+ local result = cors .get_allowed_origin (" https://te-st.com" , {" te-st.com" })
166+ luaunit .assertEquals (result , " https://te-st.com" )
167+ end
168+
160169-- this line must go at the end
161- os.exit (luaunit .LuaUnit .run ())
170+ os.exit (luaunit .LuaUnit .run ())
You can’t perform that action at this time.
0 commit comments