Skip to content

Commit c2fa21f

Browse files
authored
fix(regex): update the path segment regex (#1680)
1 parent f85adda commit c2fa21f

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

.changeset/thin-oranges-return.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@scaleway/regex': patch
3+
---
4+
5+
Update pathSegment regex

packages/regex/src/__tests__/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,9 @@ describe('@regex', () => {
969969
['hello?', false],
970970
['hello-world', true],
971971
['hello/world', false],
972+
['/', false],
973+
['a', true],
974+
['1', true],
972975
])('should match regex %s to be %s', (string, expected) => {
973976
expect(pathSegment.test(string)).toBe(expected)
974977
})

packages/regex/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,5 @@ export const reverseDNS = /^[a-z0-9-]+(\.[a-z0-9-]{1,63})+(\.)$/
8282
export const dashedIpv4 =
8383
/(\b25[0-5]|\b2[0-4][0-9]|\b[01]?[0-9][0-9]?)(-(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/
8484

85-
export const pathSegment = /^[_a-zA-Z0-9][-_.a-zA-Z0-9]*[_a-zA-Z0-9]$/
85+
export const pathSegment = /^[_a-zA-Z0-9]([-_.a-zA-Z0-9]*[_a-zA-Z0-9])?$/
8686
export const absolutePath = /^\/(([\w. -]*)[^\s?]\/?)+$/

0 commit comments

Comments
 (0)