Skip to content

Commit

Permalink
Support special characters for mapping rule wildcards in url path
Browse files Browse the repository at this point in the history
  • Loading branch information
mayorova committed May 16, 2018
1 parent 4e54345 commit 92d921f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gateway/src/apicast/mapping_rule.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ local function hash_to_array(hash)
end

local function regexpify(pattern)
return pattern:gsub('?.*', ''):gsub("{.-}", '([\\w_.-]+)'):gsub("%.", "\\.")
-- as per the RFC: https://tools.ietf.org/html/rfc3986#section-3.3
local wildcard_regex = [[([\w-.~%%!$&'()*+,;=@:]+)]] -- using long Lua brackets [[...]], escaping `%`
return pattern:gsub('?.*', ''):gsub("{.-}", wildcard_regex):gsub("%.", "\\.")
end

local regex_variable = '\\{[-\\w_]+\\}'
Expand Down
15 changes: 15 additions & 0 deletions spec/mapping_rule_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,20 @@ describe('mapping_rule', function()
local match = mapping_rule:matches('POST', '/def', { x = 'y' })
assert.is_false(match)
end)

it('returns true when wildcard value has special characters: @ : % etc.', function()
local mapping_rule = MappingRule.from_proxy_rule({
http_method = 'GET',
pattern = '/foo/{wildcard}/bar',
querystring_parameters = { },
metric_system_name = 'hits',
delta = 1
})

assert.is_true(mapping_rule:matches('GET', '/foo/a@b/bar'))
assert.is_true(mapping_rule:matches('GET', '/foo/a:b/bar'))
assert.is_true(mapping_rule:matches('GET', "/foo/a%b/bar"))
end)

end)
end)

0 comments on commit 92d921f

Please sign in to comment.