From 19d39122903e52557a608b9919f01a7ef933756e Mon Sep 17 00:00:00 2001 From: pimlie Date: Thu, 3 Aug 2017 17:20:38 +0200 Subject: [PATCH] fix for issue 1234, order less greedy routes first --- lib/common/utils.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/common/utils.js b/lib/common/utils.js index 37dcfadef2..a7ed0b67c8 100644 --- a/lib/common/utils.js +++ b/lib/common/utils.js @@ -220,17 +220,21 @@ export function createRoutes (files, srcDir) { return 1 } let res = 0 - let _a = a.path.split('/') - let _b = b.path.split('/') - for (let i = 0; i < _a.length; i++) { + const _a = a.path.split('/') + const _b = b.path.split('/') + for (let i = 0; i < _a.length >= _b.length ? _a.length : _b.length; i++) { if (res !== 0) { break } - let y = (_a[i].indexOf('*') > -1) ? 2 : (_a[i].indexOf(':') > -1 ? 1 : 0) - let z = (_b[i].indexOf('*') > -1) ? 2 : (_b[i].indexOf(':') > -1 ? 1 : 0) - res = y - z - if (i === _b.length - 1 && res === 0) { + if (i >= _a.length) { res = 1 + } else { + let y = (_a[i].indexOf('*') > -1) ? 2 : (_a[i].indexOf(':') > -1 ? 1 : 0) + let z = (_b[i].indexOf('*') > -1) ? 2 : (_b[i].indexOf(':') > -1 ? 1 : 0) + res = y - z + if (i === _b.length - 1 && res === 0) { + res = 1 + } } } return res === 0 ? -1 : res