Skip to content

Commit

Permalink
std.regex: correctly add last character of a set to regex (bugzilla 1…
Browse files Browse the repository at this point in the history
…4529)

When encounting the end of a character set ']' we have to correctly add the last
encountered valid character to the regex and resepect flags. This bug caused the
last character to not be correctly case folded if case folding was requested.

This fixes https://issues.dlang.org/show_bug.cgi?id=14529.
  • Loading branch information
David Soria Parra committed Jul 6, 2015
1 parent 227f1f2 commit 46831a4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions std/regex/internal/parser.d
Expand Up @@ -921,7 +921,7 @@ struct Parser(R)
op = Operator.Union;
goto case;
case ']':
set |= last;
addWithFlags(set, last, re_flags);
break L_CharTermLoop;
default:
addWithFlags(set, last, re_flags);
Expand Down Expand Up @@ -960,7 +960,7 @@ struct Parser(R)
op = Operator.Union;
goto case;
case ']':
set |= last;
addWithFlags(set, last, re_flags);
break L_CharTermLoop;
default:
addWithFlags(set, last, re_flags);
Expand Down
9 changes: 9 additions & 0 deletions std/regex/internal/tests.d
Expand Up @@ -955,3 +955,12 @@ unittest
assertThrown(regex(`^(x(\1))`));
assertThrown(regex(`^((x)(?=\1))`));
}

// bugzilla 14529
unittest
{
auto ctPat2 = regex(r"^[CDF]$", "i");
foreach(v; ["C", "c", "D", "d", "F", "f"])
assert(matchAll(v, ctPat2).front.hit == v);
}

0 comments on commit 46831a4

Please sign in to comment.