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

origin defaults to "null" #38

Open
gt53 opened this issue Sep 2, 2016 · 7 comments
Open

origin defaults to "null" #38

gt53 opened this issue Sep 2, 2016 · 7 comments

Comments

@gt53
Copy link

gt53 commented Sep 2, 2016

I noticed that origin defaults to "null" unlike any of the other default values that the parser returns and was wondering if that is intentional. Here's what I get when passing an empty string to the parser:

{
  protocol: '',
  slashes: false,
  hash: '',
  query: '',
  pathname: '',
  auth: '',
  host: '',
  port: '',
  hostname: '',
  password: '',
  username: '',
  origin: 'null',
  href: ''
}

Besides the inconsistency, "null" evaluates truthily, which seems potentially problematic to url-parse users.

If an empty string is ultimately desired for origin when no value is present, I can submit a PR for that.

@lpinca
Copy link
Member

lpinca commented Sep 2, 2016

As bad as it is I think it makes sense, see https://url.spec.whatwg.org/#origin. We should return an opaque origin whose value is the 'null' string.

@3rd-Eden
Copy link
Member

3rd-Eden commented Sep 2, 2016

@lpinca I'm starting to doubt here, it never says it's a string so it might have been just the null it self..

@lpinca
Copy link
Member

lpinca commented Sep 2, 2016

@3rd-Eden run new URL('file:///foo') in Firefox console and you'll see that it is a string.

@lpinca
Copy link
Member

lpinca commented Sep 2, 2016

From https://url.spec.whatwg.org/#urlutils-members

The origin attribute’s getter must return the Unicode serialization of context object’s url’s origin.

and https://html.spec.whatwg.org/multipage/browsers.html#unicode-serialisation-of-an-origin

  1. If origin is an opaque origin, then return "null".

So I think we are doing it correctly.

@lpinca
Copy link
Member

lpinca commented Sep 2, 2016

There is actually a case where browsers return an empty string for origin and that is when the URL is invalid:

> var a = document.createElement('a');
undefined
> a.href
""
> a.origin
""

so maybe we can use the empty string as well when we pass an empty string to the parser?
Another wrong behavior I noticed is the following:

> parse('sip:alice@atlanta.com')
URL {
  protocol: 'sip:',
  slashes: false,
  hash: '',
  query: '',
  pathname: '',
  auth: 'alice',
  host: 'atlanta.com',
  port: '',
  hostname: 'atlanta.com',
  password: '',
  username: 'alice',
  origin: 'sip://atlanta.com',
  href: 'sip:alice@atlanta.com' }

in this case I think origin should be 'null' as ['blob', 'ftp', 'gopher', 'http', 'https', 'ws', 'wss', 'file'].indexOf('sip') === -1.

@3rd-Eden
Copy link
Member

3rd-Eden commented Sep 2, 2016

Its that technically considered an URL?

On Sep 2, 2016, at 7:51 PM, Luigi Pinca notifications@github.com wrote:

There is actually a case where browsers return an empty string for origin and that is when the URL is invalid:

var a = document.createElement('a');
undefined
a.href
""
a.origin
""
href = 'foo'
"foo"
a.origin
""
so maybe we can use the empty string as well when we pass an empty string to the parser? Another wrong behavior I noticed is the following:

parse('sip:alice@atlanta.com')
URL {
protocol: 'sip:',
slashes: false,
hash: '',
query: '',
pathname: '',
auth: 'alice',
host: 'atlanta.com',
port: '',
hostname: 'atlanta.com',
password: '',
username: 'alice',
origin: 'sip://atlanta.com',
href: 'sip:alice@atlanta.com' }
in this case I think origin should be 'null' as ['blob', 'ftp', 'gopher', 'http', 'https', 'ws', 'wss', 'file'].indexOf('sip') === -1.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@lpinca
Copy link
Member

lpinca commented Sep 2, 2016

@3rd-Eden what are you referring to specifically? The <a> element?

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

3 participants