native-url icon indicating copy to clipboard operation
native-url copied to clipboard

Parsing of `auth` differs from Node's behaviour

Open pmmmwh opened this issue 4 years ago • 0 comments

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://:[email protected]');
// { auth: ':password', ... }

nativeUrl.parse('http://:[email protected]');
// { auth: ':password', ... }

Actual Behavior

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

url.parse('http://:[email protected]');
// { auth: ':password', ... }

nativeUrl.parse('http://:[email protected]');
// { 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

  • Version: 0.2.6
  • Platform: macOS 10.15.5

pmmmwh avatar Jul 07 '20 18:07 pmmmwh