Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing of auth differs from Node's behaviour #32

Open
pmmmwh opened this issue Jul 7, 2020 · 0 comments
Open

Parsing of auth differs from Node's behaviour #32

pmmmwh opened this issue Jul 7, 2020 · 0 comments

Comments

@pmmmwh
Copy link

pmmmwh commented Jul 7, 2020

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.

native-url/src/parse.js

Lines 188 to 191 in 0c5aec2

res.auth = [url.username, url.password]
.map(decodeURIComponent)
.filter(Boolean)
.join(':');

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant