GoogleChromeLabs / native-url

Node's url module implemented using the built-in URL API.
https://npm.im/native-url
Apache License 2.0
284 stars 11 forks source link

Parsing of `auth` differs from Node's behaviour #32

Open pmmmwh opened 4 years ago

pmmmwh commented 4 years ago

Expected Behavior

When the username is empty and a password is available, the returned value of auth should align with output from Node's url module.

const url = require('url');
const nativeUrl = require('native-url');

url.parse('http://:password@test.com');
// { auth: ':password', ... }

nativeUrl.parse('http://:password@test.com');
// { auth: ':password', ... }

Actual Behavior

const url = require('url');
const nativeUrl = require('native-url');

url.parse('http://:password@test.com');
// { auth: ':password', ... }

nativeUrl.parse('http://:password@test.com');
// { auth: 'password', ... }

Steps to Reproduce the Problem

As described in code blocks above.

The culprit is this block, where all falsy values are filtered out.

https://github.com/GoogleChromeLabs/native-url/blob/0c5aec20a765bc6a396b6066abf6951dbb5d000d/src/parse.js#L188-L191

I do think that this should technically be non-compliant with the spec (HTTP Basic Auth requires username to be defined) though ... ?

Specifications