Skip to content

Commit

Permalink
Adjusted ordering string matching to be exact when wildcard is not pr…
Browse files Browse the repository at this point in the history
…esent (#490)
  • Loading branch information
Marcus-Karl authored Aug 9, 2023
1 parent 9e3148b commit bba46b0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,28 @@ Object {
},
},
},
Object {
"_portman_operation": "POST::/crm/:id/status",
"request": Object {
"method": "POST",
"url": Object {
"path": Array [
"crm",
":id",
"status",
],
"variable": Array [
Object {
"description": "(Required) ID of the monkey you are acting upon.",
"disabled": false,
"key": "id",
"type": "any",
"value": "<string>",
},
],
},
},
},
Object {
"_portman_operation": "GET::/crm/monkies/:id",
"request": Object {
Expand Down
18 changes: 18 additions & 0 deletions src/application/globals/orderCollectionRequests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ describe('orderCollectionRequests()', () => {
'POST::/crm/{id}',
'POST::/crm/monkies/{id}',
'GET::/crm/{crmId}/monkies/{id}',
'POST::/crm/{id}/status',
'GET::/crm/monkies/{id}'
]
const obj = {
Expand All @@ -139,6 +140,23 @@ describe('orderCollectionRequests()', () => {
method: 'GET'
}
},
{
request: {
url: {
path: ['crm', ':id', 'status'],
variable: [
{
disabled: false,
type: 'any',
value: '<string>',
key: 'id',
description: '(Required) ID of the monkey you are acting upon.'
}
]
},
method: 'POST'
}
},
{
request: {
url: {
Expand Down
15 changes: 9 additions & 6 deletions src/application/globals/orderCollectionRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ export const orderCollectionRequests = (obj: any, orderOfOperations: any = []):
// Normalize orderOfOperations ({id}) to match with Postman format (:id)
const regStart = new RegExp('{', 'g')
const regEnd = new RegExp('}', 'g')
const orderOfOperationsNorm = orderOfOperations.map(item =>
item.replace(regStart, ':').replace(regEnd, '')
)
const regEx = new RegExp('/', 'g')
const orderOfOperationsNorm = orderOfOperations.map(item => {
item = item.replace(regStart, ':').replace(regEnd, '').replace(regEx, '/')

// Add string terminator for exact match if not wildcarded
return item.endsWith('*') ? item : `${item}$`
})

// Sort requests in folders
obj.item.map(pmFolder => {
Expand Down Expand Up @@ -61,9 +65,8 @@ const propComparatorPortmanOperation = (priorityArr: any): any => {
if (!Array.isArray(priorityArr)) {
return 0
}
const regEx = new RegExp('/', 'g')
const ia = priorityArr.findIndex(pri => a['_portman_operation'].match(pri.replace(regEx, '/')))
const ib = priorityArr.findIndex(pri => b['_portman_operation'].match(pri.replace(regEx, '/')))
const ia = priorityArr.findIndex(pri => a['_portman_operation'].match(pri))
const ib = priorityArr.findIndex(pri => b['_portman_operation'].match(pri))
if (ia !== -1) {
return ib !== -1 ? ia - ib : -1
}
Expand Down

0 comments on commit bba46b0

Please sign in to comment.