Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ hyper = { version = "=0.14.16", features = ["client", "http1"] }
indexmap = { version = "=1.7.0", features = ["serde-1"] }
tikv-jemallocator = { version = "=0.4.1", features = ['unprefixed_malloc_on_supported_platforms', 'profiling'] }
lettre = { version = "=0.10.0-rc.4", default-features = false, features = ["file-transport", "smtp-transport", "native-tls", "hostname", "builder"] }
license-exprs = "=1.6.0"
minijinja = "=0.8.2"
moka = "=0.6.2"
oauth2 = { version = "=4.1.0", default-features = false, features = ["reqwest"] }
Expand All @@ -78,6 +77,7 @@ sentry-conduit = { version = "=0.4.0", default-features = false }
serde = { version = "=1.0.131", features = ["derive"] }
serde_json = "=1.0.73"
sha2 = "=0.10.0"
spdx = "=0.8.0"
swirl = { git = "https://github.com/sgrif/swirl.git", rev = "e87cf37" }
tar = "=0.4.38"
tempfile = "=3.2.0"
Expand Down
23 changes: 13 additions & 10 deletions src/models/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,16 @@ impl NewVersion {
}

fn validate_license_expr(s: &str) -> AppResult<()> {
for part in s.split('/') {
license_exprs::validate_license_expr(part).map_err(|e| {
cargo_err(&format_args!("{}; see http://opensource.org/licenses for options, and http://spdx.org/licenses/ for their identifiers", e))
})?;
}
pub const PARSE_MODE: spdx::ParseMode = spdx::ParseMode {
allow_lower_case_operators: false,
allow_slash_as_or_operator: true,
allow_imprecise_license_names: false,
allow_postfix_plus_on_gpl: true,
};

spdx::Expression::parse_mode(s, PARSE_MODE).map_err(|_| {
cargo_err("unknown or invalid license expression; see http://opensource.org/licenses for options, and http://spdx.org/licenses/ for their identifiers")
})?;

Ok(())
}
Expand Down Expand Up @@ -277,13 +282,11 @@ mod tests {
assert_ok!(validate_license_expr("MIT OR Apache-2.0"));
assert_ok!(validate_license_expr("MIT/Apache-2.0"));
assert_ok!(validate_license_expr("MIT AND Apache-2.0"));
assert_ok!(validate_license_expr("MIT OR (Apache-2.0 AND MIT)"));
assert_ok!(validate_license_expr("GPL-3.0+"));

let error = assert_err!(validate_license_expr("apache 2.0"));
let error = format!("{}", error);
assert!(error.starts_with("unknown license or other term: apache; see http"));

let error = assert_err!(validate_license_expr("MIT OR (Apache-2.0 AND MIT)"));
let error = format!("{}", error);
assert!(error.starts_with("unknown license or other term: (Apache-2.0; see http"));
assert!(error.starts_with("unknown or invalid license expression; see http"));
}
}