Giter VIP home page Giter VIP logo

Comments (9)

sindilevich avatar sindilevich commented on August 21, 2024

@zipme, it looks like the URI got encoded twice. The first time it became: ... hello%20world%20here .... And then the second pass has encoded the % character and it became: ... hello%2520world%2520here .... %25 is the encoded version of the %character.

from domurl.

zipme avatar zipme commented on August 21, 2024

@sindilevich indeed, do you know if there is a quick fix for this?

from domurl.

sindilevich avatar sindilevich commented on August 21, 2024

@zipme, do you use this library with node.js?

from domurl.

zipme avatar zipme commented on August 21, 2024

@sindilevich I use it in browser

from domurl.

sindilevich avatar sindilevich commented on August 21, 2024

@zipme, I built an HTML page as follows, and used the latest url.js file as of today. It worked as expected for me: ... hello%20world%20here ....

The HTML page:

<html>

<head>
    <title>DOM URI test page</title>
    <script src="url.js"></script>
</head>

<body>
    <label>
        Enter an URI to parse:
        <input type="url" value="http://www.example.com/hello world here.jpg" class="uri-input" style="width: 100%;" />
    </label>
    <br />
    <br />
    <br />
    <label>
        The parsed URI is:
        <textarea class="uri-output" cols="80" rows="2" style="width: 100%;"></textarea>
    </label>
    <br />
    <br />
    <br />
    <button class="act-button">Act on URI</button>
    <script>
        const actButton = document.querySelector(".act-button");

        actButton.addEventListener("click", () => { 
            const uriInput = document.querySelector(".uri-input");
            const uriOutput = document.querySelector(".uri-output");
            const uri = uriInput.value;

            if (uri !== "") {
                uriOutput.value = (new URL(uri)).toString();
            }
        }, false);
    </script>
</body>

</html>

from domurl.

zipme avatar zipme commented on August 21, 2024

@sindilevich Indeed, I tried this in fiddler it does work correctly, I am using the library in a react project and here is the code snippet:

import Url from 'domurl'
new Url('http://www.example.com/hello world here.jpg').toString()
=> 'http://www.example.com/hello%2520world%2520here.jpg'

from domurl.

step307 avatar step307 commented on August 21, 2024

I've debugged a bit and found the function Url.prototype.paths a bit strange.

It seems to work as a setter for this.path by given array or as getter returning an array if nothing passed.

It looks like this function expects unescaped values.

More over the only call of this function seems to me useless:
self.paths((self.path.charAt(0) === '/' ? self.path.slice(1) : self.path).split('/') );

Basically we set this.path by array parsed from this.path. And in this case the function gets already escaped values which is not correct.

May be it should be something like:
self.paths(self.paths());
Which makes even less sense on my opinion

Whether this is required on some browsers/engines for some magic or it can be skipped.

If I delete this function or its call, all tests are passed in chrome and ff
May be IE is exactly the one who needs that.

Does anyone have any idea ?

from domurl.

step307 avatar step307 commented on August 21, 2024

Ok, not its clear IE needs this function to add starting "/"

from domurl.

step307 avatar step307 commented on August 21, 2024

Pull request: #32

from domurl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.