Skip to content

document URL parsing #2453

Closed
Closed
@PauloASilva

Description

@PauloASilva

Do you want to request a feature or report a bug?
bug

What is the current behavior?

function parseURL (url) {
    var parser = document.createElement('a');

    parser.setAttribute('href', url);

    return {
        protocol: parser.protocol,
        username: parser.username,
        password: parser.password,
        host: parser.host,
        hostname: parser.hostname,
        port: parser.port,
        pathname: parser.pathname,
        search: parser.search,
        hash: parser.hash
    };
}
Object.defineProperty(window.location, 'href', {
    writable: true,
    value: 'http://github.com'
});

parseURL('//somehost.com');
// {
//     "hash": "", 
//     "host": "", 
//     "hostname": "", 
//     "password": "", 
//     "pathname": "", 
//     "port": "", 
//     "protocol": ":", 
//     "search": "", 
//     "username": ""
// }

This is the Firefox and Google Chrome behavior when the source code runs on a page whose document.location is about:blank what is not expected as the window.location.href property is defined by (Issue#890)

Object.defineProperty(window.location, 'href', {
    writable: true,
    value: 'http://github.com'
});

If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.

What is the expected behavior?

parseURL('//somehost.com');
// {
//     protocol: "https:",
//     username: "",
//     password: "",
//     host: "somehost.com",
//     hostname: "somehost.com",
//     port: "",
//     pathname: "/",
//     search: "",
//     hash: ""
// }

This is the Firefox and Google Chrome behavior when the source code run on a page whose document.location is other than about:blank.

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.

  • Jest: v16.0.2
  • Node: v5.1.0
  • NPM: 2.14.12
  • OS: Ubuntu 16.04.1 LTS

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