Skip to content

Commit 7bb0a54

Browse files
authored
fix(cli): keep the version value when converting a string dependency to a table (#16120)
1 parent 272842a commit 7bb0a54

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-cli": patch:bug
3+
"@tauri-apps/cli": patch:bug
4+
---
5+
6+
Fix the Cargo.toml feature rewrite corrupting a string dependency version that has a trailing comment or uses single quotes (e.g. `tauri = "2" # pin` became `"2#pin"`). The version value is now kept as-is and the comment is preserved.

‎crates/tauri-cli/src/interface/rust/manifest.rs‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,10 @@ fn write_features<F: Fn(&str) -> bool>(
163163
}
164164
Value::String(version) => {
165165
let mut def = InlineTable::default();
166-
def.get_or_insert("version", version.to_string().replace(['\"', ' '], ""));
166+
def.get_or_insert("version", version.value().as_str());
167167
def.get_or_insert("features", Value::Array(toml_array(features)));
168+
// keep the surrounding whitespace and trailing comment
169+
*def.decor_mut() = version.decor().clone();
168170
*dep = Value::InlineTable(def);
169171
}
170172
_ => {
@@ -542,6 +544,35 @@ mod tests {
542544
);
543545
}
544546

547+
#[test]
548+
fn inject_features_string_keeps_version_value() {
549+
let mut manifest = r#"[dependencies]
550+
tauri = "2" # pin
551+
tauri-build = '2.1'
552+
"#
553+
.parse::<toml_edit::DocumentMut>()
554+
.unwrap();
555+
556+
let mut dependencies = vec![
557+
tauri_dependency(HashSet::from_iter(vec!["isolation".into()])),
558+
DependencyAllowlist {
559+
name: "tauri-build".into(),
560+
kind: DependencyKind::Normal,
561+
all_cli_managed_features: vec![],
562+
features: HashSet::from_iter(vec!["codegen".into()]),
563+
},
564+
];
565+
super::inject_features(&mut manifest, &mut dependencies).unwrap();
566+
567+
assert_eq!(
568+
manifest.to_string(),
569+
r#"[dependencies]
570+
tauri = { version = "2", features = ["isolation"] } # pin
571+
tauri-build = { version = "2.1", features = ["codegen"] }
572+
"#
573+
);
574+
}
575+
545576
#[test]
546577
fn inject_features_string() {
547578
inject_features(

0 commit comments

Comments
 (0)