document.location's protocol property may contain a colon #50

Closed
fidian opened this Issue Oct 29, 2012 · 2 comments

2 participants

@fidian

While playing with URI.js, I stumbled across a problem. Here's some sample code to illustrate the point, as copied from my Chrome's script console.

URI(document.location).toString()
"https:://example.com/somePage.html"

This seems to boil down to how URI handles the protocol.

URI(document.location).protocol()
"https:"

URI(document.location.toString()).protocol()
"https"

document.location.protocol
"https:"

It looks like .protocol can contain a colon and that seems to mess up URI.build on line 365:

    if (parts.protocol) {
        t += parts.protocol + ":";
    }

I'm wondering if this would make sense:

    if (parts.protocol && parts.protocol.charAt(parts.protocol.length - 1) != ':') {
        t += parts.protocol + ":";
    }
@rodneyrehm
Medialize member

Nice catch!

URI(document.location).protocol()
"https:"

URI(document.location.toString()).protocol()
"https"

gives away the reason for this: the former is an object, the latter is a string. While a string is parsed into its components, an object is not.

The problem is not with the .build() function, but with .href(). I'll look into this…

@rodneyrehm rodneyrehm added a commit that referenced this issue Nov 6, 2012
@rodneyrehm rodneyrehm fixing issue #50 - URI(location) would lead to broken URL (bad protoc…
…ol, missing query, fragment)
c027a6f
@rodneyrehm
Medialize member

Issue resolved with v1.8.0

@rodneyrehm rodneyrehm closed this Nov 13, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment