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

Cannot parse URLs that contain @ #13

Closed
JakeSidSmith opened this issue Dec 14, 2016 · 4 comments
Closed

Cannot parse URLs that contain @ #13

JakeSidSmith opened this issue Dec 14, 2016 · 4 comments

Comments

@JakeSidSmith
Copy link

JakeSidSmith commented Dec 14, 2016

I've been using your lib quite successfully until I came across a link with an @ in it.

More specifically, this is a users profile on https://medium.com/. These are formatted like: https://medium.com/@username/.

Is this something you could fix easily, or is this intended (I assume it's something to do with emails)?

@JakeSidSmith
Copy link
Author

Should I simply remove everything after the initial slash & parse that?

@sfnewzgirl
Copy link

@JakeSidSmith did that work for you? I think I might be running into the same issue.

@JakeSidSmith
Copy link
Author

@sfnewzgirl I ended up using url-parse to split the URL before running it through parse-domain. Luckily I was already using this for some other parts of my project.

I pass '/' as the first argument (pathname) to url-parse to get the root of the domain.
The second argument is the base URL.

var urlInfo = parseUrl('/', 'https://medium.com/@username/');

This gives me the following:

{
  slashes: true,
  protocol: 'http:',
  hash: '',
  query: '',
  pathname: '/',
  auth: '',
  host: 'medium.com',
  port: '',
  hostname: 'medium.com',
  password: '',
  username: '',
  origin: 'http://medium.com',
  href: 'http://medium.com/'
}

And then I parse the href into domainParse

var domain = parseDomain(urlInfo.href);

Which gives me the expected:

{
  tld: 'com',
  domain: 'medium',
  subdomain: ''
}

This may be a little heavyweight for your project if you don't need any more URL info though. You could quite easily manually split after the domain name and then call domain-parse with this.

jhnns added a commit that referenced this issue Feb 7, 2017
@jhnns
Copy link
Member

jhnns commented Feb 7, 2017

Thx for reporting this. A fix shipped with 1.1.0.

@jhnns jhnns closed this as completed Feb 7, 2017
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