Skip to content

Commit b7030c8

Browse files
fix: absolute path rule (#1605)
* fix: absolute path rule * fix: add changeset * fix: test
1 parent eff2641 commit b7030c8

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

.changeset/real-dryers-study.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@scaleway/regex': minor
3+
---
4+
5+
fix: absolute path is more permissive

packages/regex/src/__tests__/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ describe('@regex', () => {
961961
})
962962
})
963963

964-
describe.only('pathSegment', () => {
964+
describe('pathSegment', () => {
965965
test.each([
966966
['/hello', false],
967967
['hello', true],
@@ -974,14 +974,20 @@ describe('@regex', () => {
974974
})
975975
})
976976

977-
describe.only('absolutePath', () => {
977+
describe('absolutePath', () => {
978978
test.each([
979979
['/hello', true],
980+
['/a', true],
980981
['hello', false],
981-
['/hello nop', false],
982+
['/hello nop', true],
982983
['/hello?', false],
983984
['/hello-world', true],
984985
['/hello/world', true],
986+
[
987+
`/hello/world
988+
ciao/test`,
989+
false,
990+
],
985991
])('should match regex %s to be %s', (string, expected) => {
986992
expect(absolutePath.test(string)).toBe(expected)
987993
})

packages/regex/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,4 @@ 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

8585
export const pathSegment = /^[_a-zA-Z0-9][-_.a-zA-Z0-9]*[_a-zA-Z0-9]$/
86-
export const absolutePath =
87-
/^\/([_a-zA-Z0-9][-_.a-zA-Z0-9]*[_a-zA-Z0-9]\/?){1,10}$/
86+
export const absolutePath = /^\/(([\w. -]*)[^\s?]\/?)+$/

0 commit comments

Comments
 (0)