forked from 1b-agent/opencadstudio-upstream
fix(plugins): compare rustc version tokens instead of concatenating
Tightens the rustc compatibility gate so that whitespace-normalised version strings are compared token-by-token. This prevents a corner case where 'rustc 1.98.0' and 'rustc1.98.0' would be considered equal.
This commit is contained in:
1 parent
ed3e064a47
commit
4668042df5
1 file changed
+16
-4
@@ -73,15 +73,20 @@ pub fn host_rustc_version() -> &'static str {
|
|||||||
/// Returns whether two `rustc --version` outputs are considered compatible.
|
/// Returns whether two `rustc --version` outputs are considered compatible.
|
||||||
///
|
///
|
||||||
/// The full version line (e.g. "rustc 1.98.0 (hash date)") is compared
|
/// The full version line (e.g. "rustc 1.98.0 (hash date)") is compared
|
||||||
/// verbatim after normalising whitespace. This is intentionally strict: Rust
|
/// token-by-token after normalising whitespace. This is intentionally strict:
|
||||||
/// has no stable ABI, so even the same nominal compiler built in different
|
/// Rust has no stable ABI, so even the same nominal compiler built in different
|
||||||
/// environments can produce incompatible layouts.
|
/// environments can produce incompatible layouts.
|
||||||
pub fn rustc_versions_compatible(a: &str, b: &str) -> bool {
|
pub fn rustc_versions_compatible(a: &str, b: &str) -> bool {
|
||||||
if a.is_empty() || b.is_empty() {
|
if a.is_empty() || b.is_empty() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
a.split_whitespace().collect::<String>()
|
let a_tokens: Vec<&str> = a.split_whitespace().collect();
|
||||||
.eq_ignore_ascii_case(&b.split_whitespace().collect::<String>())
|
let b_tokens: Vec<&str> = b.split_whitespace().collect();
|
||||||
|
a_tokens.len() == b_tokens.len()
|
||||||
|
&& a_tokens
|
||||||
|
.iter()
|
||||||
|
.zip(b_tokens)
|
||||||
|
.all(|(a, b)| a.eq_ignore_ascii_case(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extracts the full git commit hash from a Cargo source.
|
/// Extracts the full git commit hash from a Cargo source.
|
||||||
@@ -187,6 +192,13 @@ mod tests {
|
|||||||
assert!(!rustc_versions_compatible("", ""));
|
assert!(!rustc_versions_compatible("", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rustc_version_comparison_rejects_collapsed_tokens() {
|
||||||
|
// A concatenated version must not accidentally match a spaced one.
|
||||||
|
assert!(!rustc_versions_compatible("rustc 1.98.0", "rustc1.98.0"));
|
||||||
|
assert!(!rustc_versions_compatible("rustc1.98.0", "rustc 1.98.0"));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn dependency_gate_starts_at_api_v4() {
|
fn dependency_gate_starts_at_api_v4() {
|
||||||
assert!(!uses_acadrust_gate(3));
|
assert!(!uses_acadrust_gate(3));
|
||||||
|
|||||||
Reference in new issue
Block a user