Skip to content

Commit

Permalink
Fix HTTP route sorting issue where trailing catchalls win over traili…
Browse files Browse the repository at this point in the history
…ng params; fixes #1467
  • Loading branch information
ryanblock committed Dec 2, 2023
1 parent d891c03 commit df9bac9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
13 changes: 13 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

---

## [3.6.4] 2023-12-02

### Changed

- Updated dependencies


### Fixed

- Fix HTTP route sorting issue where trailing catchalls win over trailing params; fixes #1467

---

## [3.6.3] 2023-11-19

### Changed
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"license": "Apache-2.0",
"dependencies": {
"@architect/asap": "~6.0.3",
"@architect/asap": "~6.0.4",
"@architect/parser": "~6.0.3",
"@architect/utils": "~3.1.9",
"lambda-runtimes": "~1.1.6"
Expand All @@ -32,7 +32,7 @@
"aws-sdk-mock": "~5.8.0",
"cross-env": "~7.0.3",
"dotenv": "~16.3.1",
"eslint": "~8.54.0",
"eslint": "~8.55.0",
"mock-fs": "~5.2.0",
"nyc": "~15.1.0",
"tap-arc": "^1.2.2",
Expand Down
6 changes: 6 additions & 0 deletions src/config/pragmas/sort/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ module.exports = function sortHTTP (http) {
.sort((a, b) => {
if (!a.depth && b.depth === 1 && b.trailingCapture) return -1
if (a.depth - b.depth < 0) return
if (a.depth === b.depth &&
a.trailingCapture && b.trailingCapture) {
if (a.trailingCapture === b.trailingCapture) return
if (a.trailingCapture === 'param' && b.trailingCapture === 'catchall') return -1
return 1
}
if (a.trailingCapture) return 1
if (b.trailingCapture) return -1
})
Expand Down
5 changes: 3 additions & 2 deletions test/unit/src/config/pragmas/http-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,13 @@ test('@http population: route sorting', t => {
// 2 positions
'get /api/items',
'get /api/stuff',
'get /idk/foo',
'get /:item/:idk',
'get /api/*',
// 1 position
'get /api',
'get /',
'get /:idk', // Technically invalid, since params can't live on the same level as catchalls
'get /*',
'get /:idk',

/* post */
// 5 positions
Expand Down

0 comments on commit df9bac9

Please sign in to comment.