fix(node): validate underscore rustc options

This commit is contained in:
Gatefixer
2026-08-06 07:25:21 +00:00
parent 12ee5ca626
commit dfbb5f5ade
+22 -1
View File
@@ -27,7 +27,8 @@ pub(crate) fn validate_encoded_rustflags(encoded: &str) -> Result<(), String> {
continue;
};
match name {
let name = name.replace('_', "-");
match name.as_str() {
"target-cpu" => target_cpu = Some(value),
"target-feature" => {
for toggle in value.split(',').filter(|toggle| !toggle.is_empty()) {
@@ -198,6 +199,16 @@ mod tests {
);
}
#[test]
fn rejects_underscore_spelling_above_baseline_feature() {
let flags = encoded(&["-Ctarget_cpu=x86-64-v2", "-Ctarget_feature=+apxf"]);
assert_eq!(
validate_encoded_rustflags(&flags),
Err("features above v2: apxf".to_owned())
);
}
#[test]
fn rejects_unexpected_above_baseline_feature() {
let flags = encoded(&[
@@ -241,4 +252,14 @@ mod tests {
Err("LLVM arguments can override the CPU baseline".to_owned())
);
}
#[test]
fn rejects_underscore_spelling_llvm_feature_overrides() {
let flags = encoded(&["-Ctarget_cpu=x86-64-v2", "-Cllvm_args=-mattr=+apxf"]);
assert_eq!(
validate_encoded_rustflags(&flags),
Err("LLVM arguments can override the CPU baseline".to_owned())
);
}
}