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

Add origin property #36

Closed
paulirish opened this issue Jul 27, 2016 · 4 comments
Closed

Add origin property #36

paulirish opened this issue Jul 27, 2016 · 4 comments

Comments

@paulirish
Copy link

The URL spec includes an origin property: https://url.spec.whatwg.org/#origin

This isn't currently supported in url-parse, but it'd be fantastically useful if it did. :)

@3rd-Eden
Copy link
Member

Hm, yeah it should really belong in this module. The generation of origin properties is currently deferred to the original module : https://github.com/unshiftio/original/blob/master/index.js#L15-L28 but I guess we should just deprecate that and just move over that logic to this library.

@lpinca
Copy link
Member

lpinca commented Jul 31, 2016

I see an issue with blob URLs as it seems that url-parse does not parse them correctly.

url-parse

> var URL = require('.')
undefined
> new URL('blob:https://whatwg.org/d0360e2f-caee-469f-9a2f-87d5b0456f6f')
URL {
  protocol: 'blob:',
  slashes: false,
  hash: '',
  query: '',
  pathname: '//whatwg.org/d0360e2f-caee-469f-9a2f-87d5b0456f6f',
  auth: '',
  host: 'https:',
  port: '',
  hostname: 'https:',
  password: '',
  username: '',
  href: 'blob:https://whatwg.org/d0360e2f-caee-469f-9a2f-87d5b0456f6f' }

Chrome

new URL('blob:https://whatwg.org/d0360e2f-caee-469f-9a2f-87d5b0456f6f')
URL {href: "blob:https://whatwg.org/d0360e2f-caee-469f-9a2f-87d5b0456f6f", origin: "https://whatwg.org", protocol: "blob:", username: "", password: ""}
hash: ""
host: ""
hostname: ""
href: "blob:https://whatwg.org/d0360e2f-caee-469f-9a2f-87d5b0456f6f"
origin: "https://whatwg.org"
password: ""
pathname: "https://whatwg.org/d0360e2f-caee-469f-9a2f-87d5b0456f6f"
port: ""
protocol: "blob:"
search: ""
username: ""

Node.js

> url.parse('blob:https://whatwg.org/d0360e2f-caee-469f-9a2f-87d5b0456f6f')
Url {
  protocol: 'blob:',
  slashes: null,
  auth: null,
  host: 'https',
  port: null,
  hostname: 'https',
  hash: null,
  search: null,
  query: null,
  pathname: '//whatwg.org/d0360e2f-caee-469f-9a2f-87d5b0456f6f',
  path: '//whatwg.org/d0360e2f-caee-469f-9a2f-87d5b0456f6f',
  href: 'blob:https//whatwg.org/d0360e2f-caee-469f-9a2f-87d5b0456f6f' }

so I think we should fix this first.

All other cases seem easy to handle as origin is just the result of:

url.origin = url.protocol && url.host ? `${url.protocol}//${url.host}` : 'null';

I guess we should also add the ability to set the origin using URL.prototype.set and update the relevant properties accordingly.

@3rd-Eden
Copy link
Member

@lpinca Node does have the same issue here, but that is probably something we should resolve/discuss in a different issue.

@3rd-Eden
Copy link
Member

Released 1.1.2 with a fix for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants