Skip to content

Commit

Permalink
fix(client): Remove trailing slash from /index for precise path match…
Browse files Browse the repository at this point in the history
…ing (#2344)
  • Loading branch information
poteboy authored Mar 13, 2024
1 parent 76864b4 commit 25beca8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion deno_dist/client/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions src/client/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/client/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 25beca8

Please sign in to comment.