From 9f89e0a4e0bfd9bf3759a71054c9083c96177f94 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Mon, 8 Aug 2022 15:00:37 +0100 Subject: [PATCH] option_parser: For tuple list type strip brackets only once The new option parsing for "[..,]" syntax is much stricter and requires that everything is balanced in terms of brackets. Change the stripping of the brackets to only strip the first and last one rather than multiple: e.g. "[[a,b], [c,d]]" becomes "[a,b],[c,d]" rather than "a,b], [c" Signed-off-by: Rob Bradford --- option_parser/src/lib.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/option_parser/src/lib.rs b/option_parser/src/lib.rs index e7d331cbf..3da99bbc6 100644 --- a/option_parser/src/lib.rs +++ b/option_parser/src/lib.rs @@ -305,8 +305,13 @@ impl FromStr for Tuple { fn from_str(s: &str) -> std::result::Result { let mut list: Vec<(S, T)> = Vec::new(); - let tuples_list = split_commas(s.trim().trim_matches(|c| c == '[' || c == ']')) - .map_err(TupleError::SplitOutsideBrackets)?; + let body = s + .trim() + .strip_prefix('[') + .and_then(|s| s.strip_suffix(']')) + .ok_or_else(|| TupleError::InvalidValue(s.to_string()))?; + + let tuples_list = split_commas(body).map_err(TupleError::SplitOutsideBrackets)?; for tuple in tuples_list.iter() { let items: Vec<&str> = tuple.split('@').collect();