Skip to content

Commit f67e162

Browse files
authored
Merge pull request #2 from SecJS/fix/len-match-root-path
fix: Adjust createMatcher function
2 parents 4146423 + 567572b commit f67e162

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@secjs/utils",
3-
"version": "1.2.9",
3+
"version": "1.3.0",
44
"description": "",
55
"scripts": {
66
"build": "tsc",

src/Classes/Route.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ export class Route {
137137

138138
route = routeArray.join('')
139139

140+
if (!route) route = '[/]'
141+
140142
return new RegExp(`^${route}$`)
141143
}
142144
}

tests/Classes/route.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,15 @@ describe('\n Route Class', () => {
7676
expect(matcher.test(pathTest1)).toBe(true)
7777
expect(matcher.test(pathTest2)).toBe(false)
7878
expect(matcher.test(pathTest3)).toBe(true)
79+
80+
const path2 = '/'
81+
82+
const matcher2 = route.createMatcher(path2)
83+
84+
expect(matcher2).toStrictEqual(/^[/]$/)
85+
expect(matcher2.test(path2)).toBe(true)
86+
expect(matcher2.test(pathTest1)).toBe(false)
87+
expect(matcher2.test(pathTest2)).toBe(false)
88+
expect(matcher2.test(pathTest3)).toBe(false)
7989
})
8090
})

0 commit comments

Comments
 (0)