Comments (9)
@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.
@sindilevich indeed, do you know if there is a quick fix for this?
from domurl.
@zipme, do you use this library with node.js?
from domurl.
@sindilevich I use it in browser
from domurl.
@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.
@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.
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.
Ok, not its clear IE needs this function to add starting "/"
from domurl.
Pull request: #32
from domurl.
Related Issues (20)
- Does it work with RequireJS directly? HOT 2
- Hash is encoded but... HOT 1
- Undefined variables included in query string HOT 1
- Does not work with arrays (e.g. https://example.com/?computer[desktop]=Mac) HOT 2
- How can I get url parameters?
- Current url, once initialized, is cached forever and never reflects changes to window.location.href HOT 3
- queryLength() and isEmptyQuery() returning incorrect values HOT 4
- query parameter with @ symbol not parsing correctly. HOT 1
- Expand Url Template HOT 1
- IE omits the leading slash from the pathname
- Issues when square brackets are used in parameter name HOT 4
- Small issues in encoding URLs with param values null and undefined HOT 4
- Support Protocol-relative URL (PRL) HOT 2
- Plus Sign (`+`) should not be converted to Space outside of GET values
- TypeError thrown when used inside a srcdoc iframe HOT 5
- ns.navigator is not a function when importing through webpack HOT 2
- "A security problem occurred" in Edge with @
- URL Path is over-escaped for *special characters* such as SEMICOLON, COLON, EQUALS SIGN
- Array/object url is encoded/decoded in the wrong way
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from domurl.