unshiftio / url-parse

Small footprint URL parser that works seamlessly across Node.js and browser environments.
http://unshift.io
MIT License
1.03k stars 104 forks source link

Empty query param when # is present #180

Closed ramaralo closed 5 years ago

ramaralo commented 5 years ago

When the URL contains a # and # is before query parameters, the query property returns empty : query: {}.

This test should pass:

describe('when # is before query params', function () {
    it('extracts query correctly', function () {
      const parsed = parse('https://www.google.com/#/some/path?param1=one', true);
      const expected = {
        slashes: true,
        protocol: 'https:',
        hash: '#/some/path?param1=one',
        query: {
          param1: 'one'
        },
        pathname: '/',
        auth: '',
        host: 'www.google.com',
        port: '',
        hostname: 'www.google.com',
        password: '',
        username: '',
        origin: 'https://www.google.com',
        href: 'https://www.google.com/#/some/path?param1=one' };

      assume(parsed).eql(expected);
  })});

Not sure if hash should be hash: '#/some/path?param1=one' or hash: '#/some/path' though.

3rd-Eden commented 5 years ago

I'm sorry that is simply not how URL's work. The query in your example is part of the hash. If you want to parse it out, you should run a querystring parser over the resulting hash.