0
0
mirror of https://github.com/honojs/hono.git synced 2024-11-22 11:17:33 +01:00

fix(client): Remove trailing slash from /index for precise path matching (#2344)

This commit is contained in:
poteboy 2024-03-13 17:22:45 +09:00 committed by GitHub
parent 76864b43f8
commit 25beca878f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 6 deletions

View File

@ -16,7 +16,7 @@ export const replaceUrlParam = (urlString: string, params: Record<string, string
}
export const removeIndexString = (urlSting: string) => {
return urlSting.replace(/\/index$/, '/')
return urlSting.replace(/\/index$/, '')
}
function isObject(item: unknown): item is ObjectType {

View File

@ -43,18 +43,18 @@ describe('replaceUrlParams', () => {
})
describe('removeIndexString', () => {
it('Should remove last `index` string', () => {
it('Should remove last `/index` string', () => {
let url = 'http://localhost/index'
let newUrl = removeIndexString(url)
expect(newUrl).toBe('http://localhost/')
expect(newUrl).toBe('http://localhost')
url = '/index'
newUrl = removeIndexString(url)
expect(newUrl).toBe('/')
expect(newUrl).toBe('')
url = '/sub/index'
newUrl = removeIndexString(url)
expect(newUrl).toBe('/sub/')
expect(newUrl).toBe('/sub')
url = '/subindex'
newUrl = removeIndexString(url)

View File

@ -16,7 +16,7 @@ export const replaceUrlParam = (urlString: string, params: Record<string, string
}
export const removeIndexString = (urlSting: string) => {
return urlSting.replace(/\/index$/, '/')
return urlSting.replace(/\/index$/, '')
}
function isObject(item: unknown): item is ObjectType {