Skip to content

Commit

Permalink
fix(client): shuold not remove tailing slash from top-level URL (#2523)
Browse files Browse the repository at this point in the history
* fix(client): shuold not remove tailing slash from top-level URL

* denoify
  • Loading branch information
yusukebe committed Apr 18, 2024
1 parent acb56b8 commit ed51b0b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions deno_dist/client/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export const replaceUrlProtocol = (urlString: string, protocol: 'ws' | 'http') =
}

export const removeIndexString = (urlSting: string) => {
if (/^https?:\/\/[^\/]+?\/index$/.test(urlSting)) {
return urlSting.replace(/\/index$/, '/')
}
return urlSting.replace(/\/index$/, '')
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('removeIndexString', () => {
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)
Expand Down
3 changes: 3 additions & 0 deletions src/client/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export const replaceUrlProtocol = (urlString: string, protocol: 'ws' | 'http') =
}

export const removeIndexString = (urlSting: string) => {
if (/^https?:\/\/[^\/]+?\/index$/.test(urlSting)) {
return urlSting.replace(/\/index$/, '/')
}
return urlSting.replace(/\/index$/, '')
}

Expand Down

0 comments on commit ed51b0b

Please sign in to comment.