Skip to content

Commit

Permalink
Fix/o2k allow whitespace in route paths (#4029)
Browse files Browse the repository at this point in the history
* Update path param regex to allow for whitespace characters in paths

* Update fixtures for the route path regex
  • Loading branch information
gatzjames committed Sep 20, 2021
1 parent 96fdf9d commit bc35b48
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion packages/openapi-2-kong/src/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ describe('common', () => {
describe('pathVariablesToRegex()', () => {
it('converts variables to regex path', () => {
expect(pathVariablesToRegex('/foo/{bar}/{baz}')).toBe(
'/foo/(?<bar>[^\\/\\s]+)/(?<baz>[^\\/\\s]+)$',
'/foo/(?<bar>[^\\/]+)/(?<baz>[^\\/]+)$',
);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-2-kong/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const pathVariableSearchValue = /{([^}]+)}(?!:\/\/)/g;

export function pathVariablesToRegex(p: string) {
// match anything except whitespace and '/'
const result = p.replace(pathVariableSearchValue, '(?<$1>[^\\/\\s]+)');
const result = p.replace(pathVariableSearchValue, '(?<$1>[^\\/]+)');
// add a line ending because it is a regex
return result + '$';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@
"tags": ["OAS3_import", "OAS3file_httpbin.yaml"]
}
],
"paths": ["/basic-auth/(?<user>[^\\/\\s]+)/(?<password>[^\\/\\s]+)$"]
"paths": ["/basic-auth/(?<user>[^\\/]+)/(?<password>[^\\/]+)$"]
},
{
"methods": ["GET"],
"strip_path": false,
"tags": ["OAS3_import", "OAS3file_httpbin.yaml"],
"name": "httpbin-image_format-get",
"paths": ["/image/(?<format>[^\\/\\s]+)$"]
"paths": ["/image/(?<format>[^\\/]+)$"]
},
{
"methods": ["GET"],
"strip_path": false,
"tags": ["OAS3_import", "OAS3file_httpbin.yaml"],
"name": "httpbin-delay_n-get",
"paths": ["/delay/(?<n>[^\\/\\s]+)$"]
"paths": ["/delay/(?<n>[^\\/]+)$"]
},
{
"methods": ["GET"],
Expand All @@ -55,35 +55,35 @@
"strip_path": false,
"tags": ["OAS3_import", "OAS3file_httpbin.yaml"],
"name": "httpbin-status_statusCode-delete",
"paths": ["/status/(?<statusCode>[^\\/\\s]+)$"]
"paths": ["/status/(?<statusCode>[^\\/]+)$"]
},
{
"methods": ["PUT"],
"strip_path": false,
"tags": ["OAS3_import", "OAS3file_httpbin.yaml"],
"name": "httpbin-status_statusCode-put",
"paths": ["/status/(?<statusCode>[^\\/\\s]+)$"]
"paths": ["/status/(?<statusCode>[^\\/]+)$"]
},
{
"methods": ["PATCH"],
"strip_path": false,
"tags": ["OAS3_import", "OAS3file_httpbin.yaml"],
"name": "httpbin-status_statusCode-patch",
"paths": ["/status/(?<statusCode>[^\\/\\s]+)$"]
"paths": ["/status/(?<statusCode>[^\\/]+)$"]
},
{
"methods": ["POST"],
"strip_path": false,
"tags": ["OAS3_import", "OAS3file_httpbin.yaml"],
"name": "httpbin-status_statusCode-post",
"paths": ["/status/(?<statusCode>[^\\/\\s]+)$"]
"paths": ["/status/(?<statusCode>[^\\/]+)$"]
},
{
"methods": ["GET"],
"strip_path": false,
"tags": ["OAS3_import", "OAS3file_httpbin.yaml"],
"name": "httpbin-status_statusCode-get",
"paths": ["/status/(?<statusCode>[^\\/\\s]+)$"]
"paths": ["/status/(?<statusCode>[^\\/]+)$"]
},
{
"methods": ["GET"],
Expand All @@ -105,7 +105,7 @@
}
],
"paths": [
"/hidden-basic-auth/(?<user>[^\\/\\s]+)/(?<password>[^\\/\\s]+)$"
"/hidden-basic-auth/(?<user>[^\\/]+)/(?<password>[^\\/]+)$"
]
},
{
Expand Down Expand Up @@ -161,7 +161,7 @@
"strip_path": false,
"tags": ["OAS3_import", "OAS3file_httpbin.yaml"],
"name": "httpbin-parse_machine_timestamp-get",
"paths": ["/parse/(?<machine_timestamp>[^\\/\\s]+)$"]
"paths": ["/parse/(?<machine_timestamp>[^\\/]+)$"]
},
{
"methods": ["POST"],
Expand Down Expand Up @@ -209,7 +209,7 @@
"enabled": true
}
],
"paths": ["/when/(?<human_timestamp>[^\\/\\s]+)$"]
"paths": ["/when/(?<human_timestamp>[^\\/]+)$"]
},
{
"methods": ["GET"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@
"strip_path": false,
"tags": ["OAS3_import", "OAS3file_link-example.yaml"],
"name": "Link_Example-getUserByName",
"paths": ["/2.0/users/(?<username>[^\\/\\s]+)$"]
"paths": ["/2.0/users/(?<username>[^\\/]+)$"]
},
{
"methods": ["GET"],
"strip_path": false,
"tags": ["OAS3_import", "OAS3file_link-example.yaml"],
"name": "Link_Example-getRepositoriesByOwner",
"paths": ["/2.0/repositories/(?<username>[^\\/\\s]+)$"]
"paths": ["/2.0/repositories/(?<username>[^\\/]+)$"]
},
{
"methods": ["GET"],
"strip_path": false,
"tags": ["OAS3_import", "OAS3file_link-example.yaml"],
"name": "Link_Example-getRepository",
"paths": [
"/2.0/repositories/(?<username>[^\\/\\s]+)/(?<slug>[^\\/\\s]+)$"
"/2.0/repositories/(?<username>[^\\/]+)/(?<slug>[^\\/]+)$"
]
},
{
Expand All @@ -37,7 +37,7 @@
"tags": ["OAS3_import", "OAS3file_link-example.yaml"],
"name": "Link_Example-getPullRequestsByRepository",
"paths": [
"/2.0/repositories/(?<username>[^\\/\\s]+)/(?<slug>[^\\/\\s]+)/pullrequests$"
"/2.0/repositories/(?<username>[^\\/]+)/(?<slug>[^\\/]+)/pullrequests$"
]
},
{
Expand All @@ -46,7 +46,7 @@
"tags": ["OAS3_import", "OAS3file_link-example.yaml"],
"name": "Link_Example-getPullRequestsById",
"paths": [
"/2.0/repositories/(?<username>[^\\/\\s]+)/(?<slug>[^\\/\\s]+)/pullrequests/(?<pid>[^\\/\\s]+)$"
"/2.0/repositories/(?<username>[^\\/]+)/(?<slug>[^\\/]+)/pullrequests/(?<pid>[^\\/]+)$"
]
},
{
Expand All @@ -55,7 +55,7 @@
"tags": ["OAS3_import", "OAS3file_link-example.yaml"],
"name": "Link_Example-mergePullRequest",
"paths": [
"/2.0/repositories/(?<username>[^\\/\\s]+)/(?<slug>[^\\/\\s]+)/pullrequests/(?<pid>[^\\/\\s]+)/merge$"
"/2.0/repositories/(?<username>[^\\/]+)/(?<slug>[^\\/]+)/pullrequests/(?<pid>[^\\/]+)/merge$"
]
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
"strip_path": false,
"tags": ["OAS3_import", "OAS3file_petstore-expanded.yaml"],
"name": "Swagger_Petstore-find_pet_by_id",
"paths": ["/pets/(?<id>[^\\/\\s]+)$"]
"paths": ["/pets/(?<id>[^\\/]+)$"]
},
{
"methods": ["DELETE"],
"strip_path": false,
"tags": ["OAS3_import", "OAS3file_petstore-expanded.yaml"],
"name": "Swagger_Petstore-deletePet",
"paths": ["/pets/(?<id>[^\\/\\s]+)$"]
"paths": ["/pets/(?<id>[^\\/]+)$"]
}
],
"tags": ["OAS3_import", "OAS3file_petstore-expanded.yaml"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"strip_path": false,
"tags": ["OAS3_import", "OAS3file_petstore.yaml"],
"name": "Swagger_Petstore-showPetById",
"paths": ["/pets/(?<petId>[^\\/\\s]+)$"]
"paths": ["/pets/(?<petId>[^\\/]+)$"]
}
],
"tags": ["OAS3_import", "OAS3file_petstore.yaml"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
{
"methods": ["GET"],
"name": "Example-params_pathid-get",
"paths": ["/params/(?<pathid>[^\\/\\s]+)/$"],
"paths": ["/params/(?<pathid>[^\\/]+)/$"],
"plugins": [
{
"config": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
"strip_path": false,
"tags": ["OAS3_import", "OAS3file_uspto.yaml"],
"name": "USPTO_Data_Set_API-list_searchable_fields",
"paths": ["/(?<dataset>[^\\/\\s]+)/(?<version>[^\\/\\s]+)/fields$"]
"paths": ["/(?<dataset>[^\\/]+)/(?<version>[^\\/]+)/fields$"]
},
{
"methods": ["POST"],
"strip_path": false,
"tags": ["OAS3_import", "OAS3file_uspto.yaml"],
"name": "USPTO_Data_Set_API-perform_search",
"paths": ["/(?<dataset>[^\\/\\s]+)/(?<version>[^\\/\\s]+)/records$"]
"paths": ["/(?<dataset>[^\\/]+)/(?<version>[^\\/]+)/records$"]
}
],
"tags": ["OAS3_import", "OAS3file_uspto.yaml"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const getSpecResult = (): DCService =>
name: 'My_API-birds_id-get',
strip_path: false,
methods: ['GET'],
paths: ['/birds/(?<id>[^\\/\\s]+)$'],
paths: ['/birds/(?<id>[^\\/]+)$'],
tags,
},
],
Expand Down Expand Up @@ -253,7 +253,7 @@ describe('services', () => {
tags,
name: 'My_API-birds_id-get',
methods: ['GET'],
paths: ['/birds/(?<id>[^\\/\\s]+)$'],
paths: ['/birds/(?<id>[^\\/]+)$'],
strip_path: false,
plugins: [
{
Expand Down

0 comments on commit bc35b48

Please sign in to comment.