Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support special characters for mapping rule wildcards in url path #714

Merged
merged 1 commit into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Decoded JWTs are now exposed in the policies context by the APIcast policy [PR #718](https://github.com/3scale/apicast/pull/718)
- Upgraded OpenResty to 1.13.6.2, uses OpenSSL 1.1 [PR #733](https://github.com/3scale/apicast/pull/733)
- Use forked `resty.limit.count` that uses increments instead of decrements [PR #758](https://github.com/3scale/apicast/pull/758)
- The regular expression for mapping rules has been changed, so that special characters are accepted in the wildcard values for path [PR #717](https://github.com/3scale/apicast/pull/714)

### Fixed

Expand Down
7 changes: 6 additions & 1 deletion gateway/src/apicast/mapping_rule.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ local type = type
local format = string.format
local re_match = ngx.re.match
local insert = table.insert
local re_gsub = ngx.re.gsub

local _M = {}

Expand All @@ -27,7 +28,11 @@ local function hash_to_array(hash)
end

local function regexpify(pattern)
return pattern:gsub('?.*', ''):gsub("{.-}", '([\\w_.-]+)'):gsub("%.", "\\.")
pattern = re_gsub(pattern, [[\?.*]], '', 'oj')
-- dollar sign is escaped by another $, see https://github.com/openresty/lua-nginx-module#ngxresub
pattern = re_gsub(pattern, [[\{.+?\}]], [[([\w-.~%!$$&'()*+,;=@:]+)]], 'oj')
pattern = re_gsub(pattern, [[\.]], [[\.]], 'oj')
return pattern
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)