-
Notifications
You must be signed in to change notification settings - Fork 475
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
Modifying URI should update all _parts? #58
Comments
What you want to achieve is converting something that is parsed as a relative URI (because protocol is missing) to an absolute URI. The way you described is not the way to go about this, as modifying the "atomic component" I would prefer something along the lines of URI.absoluteUri = function(uri) {
if (!uri.match(/^[a-z][a-z0-9-+-]*:\/\//i)) {
uri = "http://" + uri;
}
return URI(uri);
};
URI.absoluteUri('ExAmPle.Org:80').toString(); I'm not sure if this needs to be a core function, though. Are you performing any other operations to sanitize user input? |
Maybe a I was thinking that I could use URI.js to sanitize/validate
|
While You can do a manual re-parse any time though: var uri = new URI('ExAmPle.Org:80/a/b/c.htm?a=b#foo');
if (!uri.protocol()) {
uri.protocol('http');
}
if (!uri.protocol().match(/^https?$/i)) {
return false;
}
uri.fragment('');
// force a re-parse
uri.href(uri.href());
uri.normalize();
if(!uri.protocol() || !uri.hostname() || !uri.path()) {
//Url could not be fixed / validated
return false;
} |
👍 |
While validating and fixing user input (which is far from valid URIs always) I've come to this problem
Consider the following:
It will indeed add the protocol
http
to both the_string
and in_parts
BUT it will not rebuild the rest of the
_parts
So a call to
normalize()
will fail since_parts.hostname
=== null_parts
will look like this afteruri.protocol('http')
:When it should look like this:
It might not be a great idea (performance-wise) to re-parse the URI every time it is modified
so other ideas are welcome.
...Or another solution to this.
The text was updated successfully, but these errors were encountered: