Skip to content

Commit

Permalink
compile: support empty patterns better
Browse files Browse the repository at this point in the history
Some were rejected explicitly with this "alternations cannot currently
contain empty sub-expressions" error. Some were causing alternations to
be compiled into automaton matching a different regex.

The root of the issue is that the compilation of the Empty pattern
returns Patch { entry: self.insts.len(), .. }, that is it claims
its entry point is the next instruction. This only works if the
next instruction is unconditionally executed, which is not true for
alternations.

So we return None instead, and let the callers decide how to handle an
empty regex.

Fixes #524, Fixes #659, Closes #677
  • Loading branch information
v-gb authored and BurntSushi committed May 28, 2020
1 parent ed581f5 commit 5180a97
Show file tree
Hide file tree
Showing 2 changed files with 170 additions and 84 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,10 @@ Bug fixes:

* [BUG #523](https://github.com/rust-lang/regex/pull/523):
Add note to documentation that spaces can be escaped in `x` mode.
* [BUG #524](https://github.com/rust-lang/regex/issue/524):
Add support for empty sub-expressions, including empty alternations.
* [BUG #659](https://github.com/rust-lang/regex/issue/659):
Fix match bug caused by an empty sub-expression miscompilation.


1.3.7 (2020-04-17)
Expand Down

0 comments on commit 5180a97

Please sign in to comment.