Comments (7)
Why do you expect this?
from rust-url.
I need to wrap Url
for a Uri
type. To do so, I need a method that allows for setting the authority. It would be nice not to have to ignore errors when attempting to set an empty value when it should not be applicable.
My workaround:
if u.set_username(authority.username().unwrap_or_default())
.is_err()
{
// the url crate doesn't check for empty values before returning `Err(())`
// https://github.com/servo/rust-url/issues/844
let username = authority.username().unwrap_or_default();
if !username.is_empty() {
return Err(AuthorityError::UsernameNotAllowed(username.to_string()).into());
}
}
if u.set_password(authority.password()).is_err() {
let password = authority.password().unwrap_or_default();
if !password.is_empty() {
return Err(AuthorityError::PasswordNotAllowed(password.to_string()).into());
}
}
u.set_host(authority.host())?;
if u.set_port(authority.port()).is_err() {
if let Some(port) = authority.port() {
return Err(AuthorityError::PortNotAllowed(port).into());
}
}
from rust-url.
Or you check for the empty string before calling set_username?
from rust-url.
Sure, but that may be a valid value (as in, unsetting the username). Arguably, I could perform the same checks (!url.has_host() || url.host() == Some(Host::Domain("")) || url.scheme() == "file"
) but that leaves my side of things brittle. If additional checks are added to the url crate, I need to mirror those.
from rust-url.
We're bound to whatever the URL specification says. I'd have to check whether we can change this
from rust-url.
I think you should be able to.
This only changes whether an error is returned in the event that someone attempts to set an empty port/username/password when the port/username/password cannot be set.
On the happy path, for example when an empty string is attempted to be set for the username of a file://
url, the Url
would not be altered anyhow. The same goes for password. The call effectively becomes a no-op.
If a non-empty value is provided for either and they are not allowed, the current logic of returning an Err(())
is maintained.
from rust-url.
This also applies to set_port
from rust-url.
Related Issues (20)
- URL pathname and search setter incorrectly strips trailing spaces
- Roadmap HOT 1
- Stabilize `debugger_visualizer` feature
- InvalidPort is returned for URLs with a '#' HOT 1
- Fix `serde::Deserialize` impl for `Url` prints confusing error message
- Feature request: Provide customary RFC 3986 encoding
- Panic in set_path HOT 1
- parse: fuzzing errors
- Long URLs can cause seemingly exponential parse times, which makes untrusted input problematic
- join() broken handling of URL with colon in path HOT 4
- Integer overflow when parsing long URL HOT 4
- percent_encoding::NON_ALPHANUMERIC should be configurable
- Panicked at 'assertion failed: self.is_char_boundary(new_len)'
- Disabling "remove dot segments" behavior HOT 2
- Mark Origin::unicode_serialization as deprecated?
- Is it possible to force the %-encoding of `+`? HOT 1
- Release new version of `data-url` HOT 1
- idna::punycode::encode_str() wrong conversion ? HOT 2
- Add parameter spaceAsPlus to ByteSerialize
- Incorrect parsing of Windows drive letter quirk
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 rust-url.