-
Notifications
You must be signed in to change notification settings - Fork 98
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
Incorrect URL encoding #29
Comments
@zipme, it looks like the URI got encoded twice. The first time it became: |
@sindilevich indeed, do you know if there is a quick fix for this? |
@zipme, do you use this library with node.js? |
@sindilevich I use it in browser |
@zipme, I built an HTML page as follows, and used the latest url.js file as of today. It worked as expected for me: 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> |
@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:
|
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: 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: 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 Does anyone have any idea ? |
Ok, not its clear IE needs this function to add starting "/" |
Pull request: #32 |
When init with url like this
new Url('http://www.example.com/hello world here.jpg').toString()
returns:
http://www.example.com/hello%2520world%2520here.jpg
expected result: 'http://www.example.com/hello%20world%20here.jpg'
Not sure why the space got encoded into
%2520
When remove the protocol it works correctly:
new Url('www.example.com/hello world here.jpg').toString()
=>
'www.example.com/hello%20world%20here.jpg'
The text was updated successfully, but these errors were encountered: