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

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

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

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

fidian opened this issue Oct 29, 2012 · 2 comments

Comments

@fidian
Copy link
Contributor

fidian commented Oct 29, 2012

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
Copy link
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 added a commit that referenced this issue Nov 6, 2012
@rodneyrehm
Copy link
Member

Issue resolved with v1.8.0

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

2 participants