-
Notifications
You must be signed in to change notification settings - Fork 356
init commit to make idna optional #728
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
Changes from 1 commit
5532275
fc7dfa5
a4af4a7
1f46217
84de798
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
use crate::host::Host; | ||
use crate::parser::default_port; | ||
use crate::Url; | ||
#[cfg(feature = "idna")] | ||
use idna::domain_to_unicode; | ||
use std::sync::atomic::{AtomicUsize, Ordering}; | ||
|
||
|
@@ -93,7 +94,11 @@ impl Origin { | |
Origin::Tuple(ref scheme, ref host, port) => { | ||
let host = match *host { | ||
Host::Domain(ref domain) => { | ||
#[cfg(feature = "idna")] | ||
let (domain, _errors) = domain_to_unicode(domain); | ||
shuoli84 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#[cfg(not(feature = "idna"))] | ||
let domain = domain.clone(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like with the above comment, this should maybe panic if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If idna feature disabled, then the whole fn unicode_serialization can be opt out? I searched spec about unicode_serialization, it is strictly related with idna. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://html.spec.whatwg.org/multipage/origin.html#unicode-serialisation-of-an-origin now the spec even deletes the section of unicode serialization, just saying "There used to also be a Unicode serialization of an origin. However, it was never widely adopted." |
||
|
||
Host::Domain(domain) | ||
} | ||
_ => host.clone(), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should panic if
domain
is not ASCII? I think the rest of the code expectsHost::Domain
to hold the normalized domain name, so this way we don't introduce weird incompatibilities.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe not panic, but return an error?
Not only if the domain is not ASCII, but also if the domain contains any
xn--
labels - which we can't know if they are correct or no.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would argue panicking is correct since it's an "unrecoverable programmer error"; disabling the
idna
feature should only be done when the programmer is absolutely sure the program won't need to handle IDNs; if that assumption turns out to be false, there is no way to handle this gracefully.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I happen to be a backend engineer also, panic is the last thing I expect a base lib to do, especially when it may handle external input. I disable the idna doesn't mean I want my service panic for idna input...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
panic should used when the program enter some bad state and not easy to recover. For this case, it has no problem to recover.