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:
parent
76864b43f8
commit
25beca878f
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user