From 284e1938236c906f697de4d3c3c101c17ed5aca7 Mon Sep 17 00:00:00 2001 From: Tao Su Date: Sun, 4 Jan 2026 14:51:54 +0000 Subject: [PATCH] Support QOM format when parsing QEMU arguments --- osdk/src/config/unix_args.rs | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/osdk/src/config/unix_args.rs b/osdk/src/config/unix_args.rs index 3a63276d5..3e4e83ec5 100644 --- a/osdk/src/config/unix_args.rs +++ b/osdk/src/config/unix_args.rs @@ -28,7 +28,7 @@ pub fn split_to_kv_array(args: &str) -> Vec { && let Some(last) = joined.last_mut() { last.push(' '); - last.push_str(&elem); + last.push_str(&shlex::Quoter::new().quote(elem.as_str()).unwrap()); last_has_value = true; continue; } @@ -130,20 +130,8 @@ fn infer_multi_value_keys(array: &Vec, separator: &str) -> IndexSet Option { - let split = item.split(separator).collect::>(); - let len = split.len(); - if len > 2 || len == 0 { - error_msg!("`{}` is an invalid argument.", item); - process::exit(Errno::ParseMetadata as _); - } - - if len == 1 { - return None; - } - - let key = split.first().unwrap(); - - Some(key.to_string()) + item.split_once(separator) + .map(|(key, _value)| key.to_string()) } #[cfg(test)] @@ -194,4 +182,18 @@ pub mod test { let expected: Vec<_> = expected.iter().map(ToString::to_string).collect(); assert_eq!(expected, array); } + + #[test] + fn test_split_kv_array() { + let args = "-enable-kvm -object '{ \"qom-type\": \"tdx-guest\", \"id\": \"tdx0\", \"sept-ve-disable\": true, \"quote-generation-socket\": { \"type\": \"vsock\", \"cid\": \"2\", \"port\": \"4050\" } }'"; + + let expected = &[ + "-enable-kvm", + "-object '{ \"qom-type\": \"tdx-guest\", \"id\": \"tdx0\", \"sept-ve-disable\": true, \"quote-generation-socket\": { \"type\": \"vsock\", \"cid\": \"2\", \"port\": \"4050\" } }'", + ]; + + let array = split_to_kv_array(args); + let expected: Vec<_> = expected.iter().map(ToString::to_string).collect(); + assert_eq!(expected, array); + } }