diff --git a/src/lib/shell/flow.rs b/src/lib/shell/flow.rs index 1337fa9b36d7247b9d425f6a65de4cfda11e070e..ff34e7356f64f9aee145ae95a34c970e34d31910 100644 --- a/src/lib/shell/flow.rs +++ b/src/lib/shell/flow.rs @@ -492,6 +492,7 @@ impl<'a> Shell<'a> { /// Expand an expression and run a branch based on the value of the /// expanded expression fn execute_match>(&mut self, expression: T, cases: &[Case<'a>]) -> Result { + use regex::RegexSet; // Logic for determining if the LHS of a match-case construct (the value we are // matching against) matches the RHS of a match-case construct (a value // in a case statement). For example, checking to see if the value @@ -502,13 +503,13 @@ impl<'a> Shell<'a> { let is_array = is_array(expression.as_ref()); let value = self.expand_string(expression.as_ref())?; for case in cases.iter() { - if case - .value - .as_ref() - .and_then(|v| self.expand_string(v).ok()) - .filter(|v| v.iter().all(|v| !value.contains(v))) - .is_none() - { + if value.iter().all(|value| { + case.value + .as_ref() + .and_then(|v| self.expand_string(v).ok()) + .and_then(|v| RegexSet::new(v).ok()) + .map_or(false, |regex| regex.is_match(value)) + }) { // let pattern_is_array = is_array(&value); let previous_bind = case.binding.as_ref().and_then(|bind| { if is_array { diff --git a/tests/match.ion b/tests/match.ion index 7c4ecd465dbf197a630bd7cd2d66bce7be44eea3..d2ae63b3afb20f951e8cd3431136ac5c04329e85 100644 --- a/tests/match.ion +++ b/tests/match.ion @@ -18,6 +18,16 @@ end analyze $out1 analyze $out2 +fn analyze_regex output + match output + case ".*application/x-gzip"; echo "Use tar -xzf" + case _ ; echo "Unknown file type" + end +end + +analyze $out1 +analyze $out2 + fn wildcard input match $input case _; echo "WILDCARD!" diff --git a/tests/match.out b/tests/match.out index f967baa4009b5fe168adf5e0261b1d11db06d2c1..afc241b29a4dd7c6169a7ed2d2847e0dc5d6e18c 100644 --- a/tests/match.out +++ b/tests/match.out @@ -6,6 +6,8 @@ Odd! Even! Use tar -xzf Unknown file type +Use tar -xzf +Unknown file type WILDCARD! WILDCARD! Almost half full (or half empty)