-
-
Notifications
You must be signed in to change notification settings - Fork 62
Make fluent-uri an optional dependency with feature flag #863
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -18,7 +18,6 @@ | |
|
|
||
| use std::{convert::TryFrom, str::FromStr}; | ||
|
|
||
| use fluent_uri::UriRef as Url; | ||
| use purl::{GenericPurl, GenericPurlBuilder}; | ||
| use thiserror::Error; | ||
|
|
||
|
|
@@ -64,8 +63,9 @@ impl AsRef<str> for Purl { | |
| } | ||
| } | ||
|
|
||
| pub fn validate_uri(uri: &Uri) -> Result<(), ValidationError> { | ||
| if Url::parse(uri.0.as_str()).is_err() { | ||
| pub fn validate_uri(_uri: &Uri) -> Result<(), ValidationError> { | ||
| #[cfg(feature = "fluent-uri")] | ||
|
Contributor
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. My main concern is - if I understand it correctly - that 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. Maybe a better option here would be to condition (The outcome of that is that it would become structurally impossible to call |
||
| if fluent_uri::UriRef::parse(_uri.0.as_str()).is_err() { | ||
| return Err(ValidationError::new("Uri does not conform to RFC 3986")); | ||
| } | ||
| Ok(()) | ||
|
|
@@ -88,12 +88,13 @@ impl TryFrom<String> for Uri { | |
| type Error = UriError; | ||
|
|
||
| fn try_from(value: String) -> Result<Self, Self::Error> { | ||
| match Url::parse(value.as_str()) { | ||
| Ok(_) => Ok(Uri(value)), | ||
| Err(_) => Err(UriError::InvalidUri( | ||
| #[cfg(feature = "fluent-uri")] | ||
| if fluent_uri::UriRef::parse(value.as_str()).is_err() { | ||
| return Err(UriError::InvalidUri( | ||
| "Uri does not conform to RFC 3986".to_string(), | ||
| )), | ||
| )); | ||
| } | ||
| Ok(Uri(value)) | ||
| } | ||
| } | ||
|
|
||
|
|
||
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 honestly have no idea what best-practice is in the Rust world. This seems pretty...specific. Maybe a name like "uri-validation" might be better for this feature? And maybe it should just remove the entire function then and anything that calls it to give no false sense of security?
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.
Unfortunately, I'd say there's no really consistent idiom for feature naming in Rust -- some people prefer to give it the exact name of the dep, others prefer a descriptive name (like
uri-validation). I'm happy to do whichever one you prefer!(I see you reached the same idea about removing the entire function here, I'll go ahead with that.)