[PATCH][libcxx] regex does not handle (?=^) correctly

William Fisher william.w.fisher at gmail.com
Thu May 23 22:13:57 PDT 2013


This patch addresses http://llvm.org/bugs/show_bug.cgi?id=11118

A bug in __lookahead::exec causes /(?=^)b/ to match "ab". When
`__lookahead::__exec` makes a recursive call to
`__exp_.__match_at_start_ecma`, it passes true for the value of
`__at_first`. This causes a beginning-of-line anchor (^) inside a lookahead
assertion to match anywhere in the text.

Here is a test case (before the patch, both asserts fail).

```
#include <regex>
#include <cassert>

int main()
{
    assert(!std::regex_search("ab", std::regex("(?=^)b")));
    assert(!std::regex_search("ab", std::regex("a(?=^)b")));
}
```
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130523/fdc25a7b/attachment.html>
-------------- next part --------------
Index: include/regex
===================================================================
--- include/regex	(revision 182628)
+++ include/regex	(working copy)
@@ -2921,7 +2921,7 @@
     bool __matched = __exp_.__match_at_start_ecma(__s.__current_, __s.__last_,
                                                   __m,
                                                   __s.__flags_ | regex_constants::match_continuous,
-                                                  true);
+                                                  __s.__at_first_ && __s.__current_ == __s.__first_);
     if (__matched != __invert_)
     {
         __s.__do_ = __state::__accept_but_not_consume;


More information about the cfe-commits mailing list