chore: throw when three dot character is detected in segment (#67348)

### Why?

It could be confusing between `...` and `…`, which the later is actually
a single character.

### How?

We throw if we detect `…` instead of `...`.
This commit is contained in:
Jiwon Choi 2024-07-02 00:53:45 +09:00 committed by GitHub
parent 78dc2db916
commit f702a14acf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View file

@ -94,6 +94,12 @@ class UrlNode {
isOptional = true
}
if (segmentName.startsWith('…')) {
throw new Error(
`Detected a three-dot character ('…') at ('${segmentName}'). Did you mean ('...')?`
)
}
if (segmentName.startsWith('...')) {
// Strip `...`, leaving only `something`
segmentName = segmentName.substring(3)

View file

@ -213,4 +213,10 @@ describe('getSortedRoutes', () => {
])
).toThrow(/differ only by non-word/)
})
it('catches param names start with three-dot character not actual three dots', () => {
expect(() => getSortedRoutes(['[…three-dots]'])).toThrow(
/Detected a three-dot character/
)
})
})