From df9bac9bf80e2521a94e73491fa299a14f0428c7 Mon Sep 17 00:00:00 2001 From: Ryan Block Date: Sat, 2 Dec 2023 14:24:20 -0800 Subject: [PATCH] Fix HTTP route sorting issue where trailing catchalls win over trailing params; fixes #1467 --- changelog.md | 13 +++++++++++++ package.json | 4 ++-- src/config/pragmas/sort/http.js | 6 ++++++ test/unit/src/config/pragmas/http-test.js | 5 +++-- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/changelog.md b/changelog.md index 56135c5..d8f0af7 100644 --- a/changelog.md +++ b/changelog.md @@ -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 diff --git a/package.json b/package.json index 62d988e..0ab9785 100644 --- a/package.json +++ b/package.json @@ -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" @@ -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", diff --git a/src/config/pragmas/sort/http.js b/src/config/pragmas/sort/http.js index d9ce83b..2baeec0 100644 --- a/src/config/pragmas/sort/http.js +++ b/src/config/pragmas/sort/http.js @@ -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 }) diff --git a/test/unit/src/config/pragmas/http-test.js b/test/unit/src/config/pragmas/http-test.js index 18d522d..569fb73 100644 --- a/test/unit/src/config/pragmas/http-test.js +++ b/test/unit/src/config/pragmas/http-test.js @@ -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