diff options
author | Marc Tiehuis <marctiehuis@gmail.com> | 2017-03-04 21:40:19 +1300 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2017-03-08 10:13:28 -0500 |
commit | 066f97d85553f12696272086d26fa86fc2c84d9e (patch) | |
tree | b6701e9c3badf2ddac31fa4ef824913c5049b050 /globset | |
parent | df1bf4a042160e0b9b1a1d05de68f0ffcb6c66f0 (diff) |
Add enclosing group to alternations in globs
Fixes #391.
Diffstat (limited to 'globset')
-rw-r--r-- | globset/src/glob.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/globset/src/glob.rs b/globset/src/glob.rs index 42d651fd..fbfc7d9b 100644 --- a/globset/src/glob.rs +++ b/globset/src/glob.rs @@ -659,9 +659,18 @@ impl Tokens { for pat in patterns { let mut altre = String::new(); self.tokens_to_regex(options, &pat, &mut altre); - parts.push(altre); + if !altre.is_empty() { + parts.push(altre); + } + } + + // It is possible to have an empty set in which case the + // resulting alternation '()' would be an error. + if !parts.is_empty() { + re.push('('); + re.push_str(&parts.join("|")); + re.push(')'); } - re.push_str(&parts.join("|")); } } } |