Skip to content

Merging URL Components #530

@nainemom

Description

@nainemom

Environment

Runtime: Browser
Browser Version: Google Chrome: Version 142.0.7444.175 (Official Build) (64-bit)

Reproduction

import { ofetch } from "ofetch";

ofetch('/path', {
  baseURL: 'https://example.org/',
  query: {
    q: 'y',
  },
  onRequest: [({ request }) => {
    console.log(request.toString()); // https://example.org/path?q=y
  }]
});

ofetch('/path', {
  baseURL: 'https://example.org/\r',
  query: {
    q: 'y',
  },
  onRequest: [({ request }) => {
    console.log(request.toString()); // https://example.org/?q=y
  }]
});

Describe the bug

Merging URL components doesn’t work correctly in some scenarios. For example, when the baseURL ends with \r (e.g. 'https://example.org/\r'), ofetch completely skips the path part and only appends the query parameters to the base URL. However, if the request has no query parameters, it still works, even with the \r at the end.

Additional context

The \r ending character was a .env parsing mistake.

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions