Skip to content

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

@fidian

Description

@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 + ":";
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions