Skip to content

Commit e02eb2e

Browse files
committed
Make fluent-uri an optional dependency, enabled by default
This allows downstream users to disable the `fluent-uri` feature to remove the dependency when URI validation is not needed. https://claude.ai/code/session_01H51ccpYf6jhtzujzWiypPc
1 parent e58bd55 commit e02eb2e

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

cyclonedx-bom/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ license.workspace = true
1414
repository.workspace = true
1515
rust-version.workspace = true
1616

17+
[features]
18+
default = ["fluent-uri"]
19+
fluent-uri = ["dep:fluent-uri"]
20+
1721
[dependencies]
1822
base64 = "0.22.1"
19-
fluent-uri = "0.4.1"
23+
fluent-uri = { version = "0.4.1", optional = true }
2024
indexmap = "2.2.2"
2125
once_cell = "1.18.0"
2226
ordered-float = { version = "5.0.0", default-features = false }

cyclonedx-bom/src/external_models/uri.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
use std::{convert::TryFrom, str::FromStr};
2020

21-
use fluent_uri::UriRef as Url;
2221
use purl::{GenericPurl, GenericPurlBuilder};
2322
use thiserror::Error;
2423

@@ -64,8 +63,9 @@ impl AsRef<str> for Purl {
6463
}
6564
}
6665

67-
pub fn validate_uri(uri: &Uri) -> Result<(), ValidationError> {
68-
if Url::parse(uri.0.as_str()).is_err() {
66+
pub fn validate_uri(_uri: &Uri) -> Result<(), ValidationError> {
67+
#[cfg(feature = "fluent-uri")]
68+
if fluent_uri::UriRef::parse(_uri.0.as_str()).is_err() {
6969
return Err(ValidationError::new("Uri does not conform to RFC 3986"));
7070
}
7171
Ok(())
@@ -88,12 +88,13 @@ impl TryFrom<String> for Uri {
8888
type Error = UriError;
8989

9090
fn try_from(value: String) -> Result<Self, Self::Error> {
91-
match Url::parse(value.as_str()) {
92-
Ok(_) => Ok(Uri(value)),
93-
Err(_) => Err(UriError::InvalidUri(
91+
#[cfg(feature = "fluent-uri")]
92+
if fluent_uri::UriRef::parse(value.as_str()).is_err() {
93+
return Err(UriError::InvalidUri(
9494
"Uri does not conform to RFC 3986".to_string(),
95-
)),
95+
));
9696
}
97+
Ok(Uri(value))
9798
}
9899
}
99100

0 commit comments

Comments
 (0)