Skip to content

Commit

Permalink
Fix the validation for optional dep
Browse files Browse the repository at this point in the history
Signed-off-by: hi-rustin <[email protected]>
  • Loading branch information
Rustin170506 committed Nov 8, 2023
1 parent c4f3be2 commit 8753f8a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/models/krate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,14 @@ impl Crate {

/// Validates a whole feature string, `features = ["THIS", "and/THIS", "dep:THIS", "dep?/THIS"]`.
pub fn valid_feature(name: &str) -> AppResult<()> {
match name.split_once('/') {
Some((dep, dep_feat)) => {
let dep = dep.strip_suffix('?').unwrap_or(dep);
Crate::valid_dependency_name(dep)?;
Crate::valid_feature_name(dep_feat)
}
None => Crate::valid_feature_name(name.strip_prefix("dep:").unwrap_or(name)),
if let Some((dep, dep_feat)) = name.split_once('/') {
let dep = dep.strip_suffix('?').unwrap_or(dep);
Crate::valid_dependency_name(dep)?;
Crate::valid_feature_name(dep_feat)
} else if let Some((_, dep)) = name.split_once("dep:") {
Crate::valid_dependency_name(dep)
} else {
Crate::valid_feature_name(name)
}
}

Expand Down Expand Up @@ -587,5 +588,7 @@ mod tests {
assert!(Crate::valid_feature("foo?bar").is_err());
assert!(Crate::valid_feature("bar.web").is_ok());
assert!(Crate::valid_feature("foo/bar.web").is_ok());
assert!(Crate::valid_feature("dep:0foo").is_err());
assert!(Crate::valid_feature("0foo?/bar.web").is_err());
}
}

0 comments on commit 8753f8a

Please sign in to comment.