From 4c2328b72350027be48564a31b986a6be83b51d9 Mon Sep 17 00:00:00 2001 From: Pascal Scholz Date: Tue, 7 Jul 2026 10:25:17 +0200 Subject: [PATCH] option_parser: Trim whitespace from `TupleList` elements Whitespace around `TupleList` elements can lead to errors while parsing the contained `Tuple` keys and values. In some cases, whitespace in input can lead to different parsing results for semantically identical keys or values, e.g. "id1" and "id1 ". We therefore trim whitespace from `TupleList` elements. Signed-off-by: Pascal Scholz On-behalf-of: SAP pascal.scholz@sap.com --- option_parser/src/lib.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/option_parser/src/lib.rs b/option_parser/src/lib.rs index 12dbe1719..ea9d7c306 100644 --- a/option_parser/src/lib.rs +++ b/option_parser/src/lib.rs @@ -530,7 +530,7 @@ impl Parseable for TupleList { .ok_or_else(|| TupleError::UnbalancedOutsideBrackets(s.to_string()))?; let tuples_raw = split_commas(body).map_err(TupleError::SplitInsideBrackets)?; for tuple_raw in tuples_raw.iter() { - list.push(Tuple::from_str(tuple_raw)?); + list.push(Tuple::from_str(tuple_raw.trim())?); } Ok(TupleList(list)) @@ -868,6 +868,21 @@ mod unit_tests { ); } + #[test] + fn test_tuple_list_trim_whitespace() { + let t = TupleList::>::from_str("[a@[1,2], b@[3,4] ,\tc@[5,6],\nd@[7,8]]") + .unwrap(); + assert_eq!( + t, + TupleList(vec![ + Tuple("a".to_owned(), vec![1, 2]), + Tuple("b".to_owned(), vec![3, 4]), + Tuple("c".to_owned(), vec![5, 6]), + Tuple("d".to_owned(), vec![7, 8]), + ]) + ); + } + #[test] fn test_tuple_missing_at_separator() { Tuple::::from_str("foo42").unwrap_err();