Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

URL.parse fails on valid query/path with single quote character #954

Closed
hueniverse opened this issue Apr 19, 2011 · 1 comment
Closed

URL.parse fails on valid query/path with single quote character #954

hueniverse opened this issue Apr 19, 2011 · 1 comment

Comments

@hueniverse
Copy link

Parsing of URIs with valid single-quote character in path or query fails. For example:

http://x/path?message=that's&x=4#frag

RFC 3986 allows the following characters:

  pchar         = unreserved / pct-encoded / sub-delims / ":" / "@"
  unreserved  = ALPHA / DIGIT / "-" / "." / "_" / "~"
  sub-delims  = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
  query       = *( pchar / "/" / "?" )

However the delims variable incorrectly includes single-quote which is allowed:

delims = ['<', '>', '"', '\'', '`', /\s/],

The delims variable is used here:

  // chop off any delim chars.
  if (!unsafeProtocol[lowerProto]) {
    var chop = rest.length;
    for (var i = 0, l = delims.length; i < l; i++) {
      var c = rest.indexOf(delims[i]);
      if (c !== -1) {
        chop = Math.min(c, chop);
      }
    }
    rest = rest.substr(0, chop);
    out.href += rest;
  }

Which is messing with the path, query, and fragment, even though that code was added to make the host parsing safe per issue 711.

I'm not sure what this code is actually for, but it is chopping off valid URI components if they include a legal single-quote.

@isaacs
Copy link

isaacs commented Apr 20, 2011

Got a patch that fixes this, and found a few other little nits while I was in there. Update forthcoming.

@isaacs isaacs closed this as completed in 90802d6 Apr 20, 2011
isaacs added a commit that referenced this issue May 10, 2011
The change for #954 introduced a regression that would cause
the url parser to fail on special chars found in the auth
segment.  Fix that, and also don't create invalid urls when
format() is called on an object containing an auth member
containing '@' characters or delimiters.
isaacs added a commit to isaacs/node-v0.x-archive that referenced this issue May 27, 2011
The change for nodejs#954 introduced a regression that would cause
the url parser to fail on special chars found in the auth
segment.  Fix that, and also don't create invalid urls when
format() is called on an object containing an auth member
containing '@' characters or delimiters.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants