Skip to content

v3 incorrectly strips out question mark from URL when no query params after question mark #776

@dzek69

Description

@dzek69

This bug is somehow related to #749

When I want to get an url like that: "https://example.com/resource?" the path sent to the server should include a question mark, even I specified no parameters. v3 node-fetch strips question mark out. Similar issue for python library, where question if this should be included or not has already been discussed is here: psf/requests#2912, especially see this: psf/requests#2912 (comment) - tl;dr spec defines that question mark should be included in this case

This works as expected in node-fetch v2 and of course works as expected in browser "real" fetch

Demo code for node:

const fetch = require("node-fetch").default;

(async () => {
    const ny = await fetch("https://s.o7o.pl/cUNtAD?").then(r => r.text());
    console.log("is result ok?", ny.includes("s.o7o.pl"));
})().catch(e => console.error("main", e));

Demo for "real" fetch in browser:

  • head to https://s.o7o.pl/ (to avoid CORS issues)
  • open dev tools console
  • paste code from node demo, but strip out require line

Explaination of demo:
s.o7o.pl is a private use url shortener, under URL: https://s.o7o.pl/cUNtAD there is redirection to npmjs.com page, but when question mark is added to url then html page with target url is shown instead (similar to bit.ly behavior, but they use "+" sign). Some other APIs may rely on that.

PR incoming.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions