From 227f043f4f4769018143ac5a70d49ce1ffe379e8 Mon Sep 17 00:00:00 2001 From: Ben Beasley Date: Mon, 11 Nov 2024 03:31:03 -0500 Subject: [PATCH] Update goblin to 0.9 (#711) --- Cargo.lock | 4 +- Cargo.toml | 3 +- src/licenses/gather.rs | 120 ++++++++++++++++++++--------------------- 3 files changed, 62 insertions(+), 65 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0c636ea2..c76633fe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1518,9 +1518,9 @@ dependencies = [ [[package]] name = "goblin" -version = "0.8.2" +version = "0.9.2" source = "registry+/~https://github.com/rust-lang/crates.io-index" -checksum = "1b363a30c165f666402fe6a3024d3bec7ebc898f96a4a23bd1c99f8dbf3f4f47" +checksum = "53ab3f32d1d77146981dea5d6b1e8fe31eedcb7013e5e00d6ccd1259a4b4d923" dependencies = [ "log", "plain", diff --git a/Cargo.toml b/Cargo.toml index 586e0e67..5fdc46dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,13 +65,14 @@ fern = "0.6" # Glob matching globset = "0.4" # Native executable detection -goblin = { version = "0.8", default-features = false, features = [ +goblin = { version = "0.9", default-features = false, features = [ "elf32", "elf64", "mach32", "mach64", "pe32", "pe64", + "te", ] } # We need to figure out HOME/CARGO_HOME in some cases home = "0.5" diff --git a/src/licenses/gather.rs b/src/licenses/gather.rs index 4aa85dfc..b144c31b 100644 --- a/src/licenses/gather.rs +++ b/src/licenses/gather.rs @@ -613,22 +613,58 @@ impl Gatherer { // 2 TODO // 3 - match &krate.license { - Some(license_field) => { - // Reasons this can fail: - // - // * Empty! The rust crate used to validate this field has a bug - // /~https://github.com/rust-lang-nursery/license-exprs/issues/23 - // * It also just does basic lexing, so parens, duplicate operators, - // unpaired exceptions etc can all fail validation - // - // Note that these only apply to _old_ versions, as `spdx` - // is now used by crates.io to validate, but it uses lax - // rules to allow some license identifiers that aren't - // technically correct - - match spdx::Expression::parse(license_field) { - Ok(validated) => { + if let Some(license_field) = &krate.license { + // Reasons this can fail: + // + // * Empty! The rust crate used to validate this field has a bug + // /~https://github.com/rust-lang-nursery/license-exprs/issues/23 + // * It also just does basic lexing, so parens, duplicate operators, + // unpaired exceptions etc can all fail validation + // + // Note that these only apply to _old_ versions, as `spdx` + // is now used by crates.io to validate, but it uses lax + // rules to allow some license identifiers that aren't + // technically correct + + match spdx::Expression::parse(license_field) { + Ok(validated) => { + let (id, span) = get_span("license"); + + return KrateLicense { + krate, + lic_info: LicenseInfo::SpdxExpression { + expr: validated, + nfo: LicenseExprInfo { + file_id: id, + offset: span.start, + source: LicenseExprSource::Metadata, + }, + }, + labels, + notes: Vec::new(), + }; + } + Err(err) => { + let (id, lic_span) = get_span("license"); + let lic_span = + lic_span.start + err.span.start..lic_span.start + err.span.end; + + labels.push( + Label::secondary(id, lic_span).with_message(err.reason.to_string()), + ); + + // If we fail strict parsing, attempt to use lax parsing, + // though still emitting a warning so the user is aware + if let Ok(validated) = spdx::Expression::parse_mode( + license_field, + spdx::ParseMode { + allow_lower_case_operators: true, + // We already force correct this when loading crates + allow_slash_as_or_operator: false, + allow_imprecise_license_names: true, + allow_postfix_plus_on_gpl: true, + }, + ) { let (id, span) = get_span("license"); return KrateLicense { @@ -645,54 +681,14 @@ impl Gatherer { notes: Vec::new(), }; } - Err(err) => { - let (id, lic_span) = get_span("license"); - let lic_span = - lic_span.start + err.span.start..lic_span.start + err.span.end; - - labels.push( - Label::secondary(id, lic_span) - .with_message(err.reason.to_string()), - ); - - // If we fail strict parsing, attempt to use lax parsing, - // though still emitting a warning so the user is aware - if let Ok(validated) = spdx::Expression::parse_mode( - license_field, - spdx::ParseMode { - allow_lower_case_operators: true, - // We already force correct this when loading crates - allow_slash_as_or_operator: false, - allow_imprecise_license_names: true, - allow_postfix_plus_on_gpl: true, - }, - ) { - let (id, span) = get_span("license"); - - return KrateLicense { - krate, - lic_info: LicenseInfo::SpdxExpression { - expr: validated, - nfo: LicenseExprInfo { - file_id: id, - offset: span.start, - source: LicenseExprSource::Metadata, - }, - }, - labels, - notes: Vec::new(), - }; - } - } } } - None => { - let (id, lic_span) = get_span("license"); - labels.push( - Label::secondary(id, lic_span) - .with_message("license expression was not specified"), - ); - } + } else { + let (id, lic_span) = get_span("license"); + labels.push( + Label::secondary(id, lic_span) + .with_message("license expression was not specified"), + ); } // 4