defunctzombie / node-url

node.js core url module as a module
MIT License
375 stars 96 forks source link

Bug with url.format and object contain colon #67

Closed eduardoPavon closed 10 months ago

eduardoPavon commented 10 months ago

Hello,

It seems there's a bug in the new version of the library '0.11.2'. In this update, consistency was maintained among the array-type parameters. However, it seems this consistency has been broken for parameters that make use of colons (:)

Example:

import * as url0 from "https://cdn.skypack.dev/url@0.11.0";
import * as url1 from "https://cdn.skypack.dev/url@0.11.1";
import * as url2 from "https://cdn.skypack.dev/url@0.11.2";

const query = {"custom:id":"12"}

const data = {
    protocol: window.location.protocol,
    host: window.location.host,
    pathname: 'test',
    query: query,
  }
console.log({
  url0: url0.format(data),
  url1: url1.format(data),
  url2: url2.format(data)
});

Output:

{
    "url0": "https://cdpn.io/test?custom%3Aid=12",
    "url1": "https://cdpn.io/test?custom%3Aid=12",
    "url2": "https://cdpn.io/test?custom:id=12"
}
ljharb commented 10 months ago

hmm, that's caused by encodeValuesOnly. I'm not sure why i added that in 4cec245; i'll add a test and remove it.