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

WHATWG URL inconsistent 'origin' property #21955

Closed
mattyclarkson opened this issue Jul 24, 2018 · 8 comments
Closed

WHATWG URL inconsistent 'origin' property #21955

mattyclarkson opened this issue Jul 24, 2018 · 8 comments
Labels
whatwg-url Issues and PRs related to the WHATWG URL implementation.

Comments

@mattyclarkson
Copy link

mattyclarkson commented Jul 24, 2018

The whatwg-url npm package and URL class in Chrome/Safari perform the following with file:// URLs:

const url = new URL('file:///private/abc/music.aac');
console.log(url.origin);  // -> 'file://'

However, the built-in 'url' module and Firefox perform the following:

const url = new URL('file:///private/abc/music.aac');
console.log(url.origin);  // -> null

There is an inconsistency here. I had a look at the internal url.js and I'm not sure if the specification allows an opaque origin in this situation. I'd thought I report in case someone more familiar with the specification can determine if the inconsistency is allowed by the specification.

@addaleax
Copy link
Member

/cc @nodejs/url

@addaleax addaleax added the whatwg-url Issues and PRs related to the WHATWG URL implementation. label Jul 24, 2018
@TimothyGu
Copy link
Member

This is unfortunately one of the unspecified areas in the URL Standard. See https://url.spec.whatwg.org/#concept-url-origin:

A URL’s origin is the origin returned by running these steps, switching on URL’s scheme:

"file"
Unfortunate as it is, this is left as an exercise to the reader. When in doubt, return a new opaque origin.

We followed the "when in doubt" instruction, but it did come as a surprise to me to find that whatwg-url doesn't.

@TimothyGu
Copy link
Member

Firefox also returns null. Safari and Chrome both return "file://". Ugh.

@mattyclarkson
Copy link
Author

Yup, seems like NodeJS is more inline with the specification. Is it worth moving upstream to Safari, Chrome, WHATWG URL to see what they think? I imagine there would be resistance to change as it might break backwards compatibility and, as it reads, they are compliant. I feel like the spec should really be tightened up there and just make everything return a null; you could return anything you like as a result of the exercise.

@mattyclarkson
Copy link
Author

mattyclarkson commented Jul 25, 2018

Have updated the OP with the new information about the inconsistencies.

@TimothyGu
Copy link
Member

I don't think getting browsers to align with each other is within the scope of this project. I am pretty certain what we do is a fair behavior, and I'm going to file an issue at whatwg-url encouraging them to do the same as we do (pretty sure they'd agree), and then close this issue.

How's that sound?

@mattyclarkson
Copy link
Author

Yup, totally on-board with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
whatwg-url Issues and PRs related to the WHATWG URL implementation.
Projects
None yet
Development

No branches or pull requests

3 participants