Skip to content

fix(useFetch): ensure single slash #4296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 19, 2024
Merged

fix(useFetch): ensure single slash #4296

merged 3 commits into from
Nov 19, 2024

Conversation

mrchar
Copy link
Contributor

@mrchar mrchar commented Oct 23, 2024

Description

When I call createFetch with a baseUrl that ends with a slash, and call useFetch with a path that starts with a slash, it will send a request like https://example.com//api/something.

This PR resolves this problem by checking if both the start and end have slashes, and removing the starting slash.

function joinPaths(start: string, end: string): string {
  if (!start.endsWith('/') && !end.startsWith('/')) {
    return `${start}/${end}`
  }

  if (start.endsWith('/') && end.startsWith('/')) {
    return `${start.slice(0, start.length - 1)}${end}`
  }

  return `${start}${end}`
}

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Oct 23, 2024
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 19, 2024
@antfu antfu enabled auto-merge November 19, 2024 06:19
@antfu antfu added this pull request to the merge queue Nov 19, 2024
Merged via the queue into vueuse:main with commit 3de6872 Nov 19, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy