fix(api-gateway): non-greedy route pattern regex #533
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #, if available: #520
Description of changes:
This fixes a regex bug that used a greedy pattern ending with incorrect path resolution, as any path after a pattern would be included in the argument.
Excerpt:
In this example, say we have a GET request as
/accounts/123
and another as/accounts/123/source_networks
, we'd have the following effect prior to this fix:r'^/accounts/(?P<account_id>.+)$'
123
r'^/accounts/(?P<account_id>.+)/source_networks$'
123/source_networks
With this fix,
account_id
parameter would be 123 in both occasions due to word boundary not being non-greedy. This also allows an arbitrary number of dynamic route paths and static route paths.r'^/accounts/(?P<account_id>\\w+\\b)$'
123
r'^/accounts/(?P<account_id>\\w+\\b)/source_networks$'
123
Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.