Skip to content

Commit

Permalink
fix: remove url deserialization from path
Browse files Browse the repository at this point in the history
  • Loading branch information
ruben-arts committed Jul 25, 2024
1 parent 5e3ed43 commit ecc6a85
Showing 1 changed file with 0 additions and 54 deletions.
54 changes: 0 additions & 54 deletions crates/rattler_conda_types/src/match_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ pub struct MatchSpec {
#[serde_as(as = "Option<SerializableHash::<rattler_digest::Sha256>>")]
pub sha256: Option<Sha256Hash>,
/// The url of the package
#[serde(deserialize_with = "deserialize_url")]
pub url: Option<Url>,
}

Expand Down Expand Up @@ -257,7 +256,6 @@ pub struct NamelessMatchSpec {
#[serde_as(as = "Option<SerializableHash::<rattler_digest::Sha256>>")]
pub sha256: Option<Sha256Hash>,
/// The url of the package
#[serde(deserialize_with = "deserialize_url")]
pub url: Option<Url>,
}

Expand Down Expand Up @@ -349,19 +347,6 @@ where
}
}

/// Deserialize matchspec url from string
fn deserialize_url<'de, D>(deserializer: D) -> Result<Option<Url>, D::Error>
where
D: Deserializer<'de>,
{
let s: Option<String> = Option::deserialize(deserializer)?;

match s {
None => Ok(None),
Some(s) => parse::parse_url_like(s.as_ref()).map_err(serde::de::Error::custom),
}
}

/// A trait that defines the behavior of matching a spec against a record.
pub trait Matches<T> {
/// Match a [`MatchSpec`] against a record.
Expand Down Expand Up @@ -640,43 +625,4 @@ mod tests {
.collect::<Vec<String>>()
.join("\n"));
}

#[test]
fn test_deserialize_url_in_nameless_match_spec() {
// Test with a valid URL
let json = json!({
"url": "https://test.com/conda/file-0.1-bla_1.conda"
});
let result: Result<NamelessMatchSpec, _> = serde_json::from_value(json);
assert_eq!(
result.unwrap().url.unwrap().as_str(),
"https://test.com/conda/file-0.1-bla_1.conda"
);

// Test with a valid file path
let json = json!({
"url": "/home/user/file.conda"
});
let result: Result<NamelessMatchSpec, _> = serde_json::from_value(json);
assert_eq!(
result.unwrap().url.unwrap().as_str(),
"file:///home/user/file.conda"
);

// Test with a valid windows path
let json = json!({
"url": "C:\\Users\\user\\file.conda"
});
let result: Result<NamelessMatchSpec, _> = serde_json::from_value(json);
assert_eq!(
result.unwrap().url.unwrap().as_str(),
"file:///C:/Users/user/file.conda"
);
// Test with None
let json = json!({
"url": null
});
let result: Result<NamelessMatchSpec, _> = serde_json::from_value(json);
assert!(result.unwrap().url.is_none());
}
}

0 comments on commit ecc6a85

Please sign in to comment.