mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 06:30:28 +03:00
Fix issue 17673 - wrong whichPattern in multi-regex with alteration
This commit is contained in:
parent
b91f05356e
commit
5fbab17c47
2 changed files with 21 additions and 3 deletions
|
@ -1087,10 +1087,10 @@ alias Sequence(int B, int E) = staticIota!(B, E);
|
||||||
@safe unittest
|
@safe unittest
|
||||||
{
|
{
|
||||||
import std.algorithm.searching : canFind;
|
import std.algorithm.searching : canFind;
|
||||||
void willThrow(T)(T arg, string msg)
|
void willThrow(T, size_t line = __LINE__)(T arg, string msg)
|
||||||
{
|
{
|
||||||
auto e = collectException(regex(arg));
|
auto e = collectException(regex(arg));
|
||||||
assert(e.msg.canFind(msg), e.msg);
|
assert(e.msg.canFind(msg), to!string(line) ~ ": " ~ e.msg);
|
||||||
}
|
}
|
||||||
willThrow([r".", r"[\(\{[\]\}\)]"], "no matching ']' found while parsing character class");
|
willThrow([r".", r"[\(\{[\]\}\)]"], "no matching ']' found while parsing character class");
|
||||||
willThrow([r"[\", r"123"], "no matching ']' found while parsing character class");
|
willThrow([r"[\", r"123"], "no matching ']' found while parsing character class");
|
||||||
|
@ -1106,3 +1106,15 @@ alias Sequence(int B, int E) = staticIota!(B, E);
|
||||||
auto e = collectException!RegexException(regex(q"<[^]>"));
|
auto e = collectException!RegexException(regex(q"<[^]>"));
|
||||||
assert(e.msg.canFind("no operand for '^'"));
|
assert(e.msg.canFind("no operand for '^'"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bugzilla 17673
|
||||||
|
@safe unittest
|
||||||
|
{
|
||||||
|
string str = `<">`;
|
||||||
|
string[] regexps = ["abc", "\"|x"];
|
||||||
|
auto regexp = regex(regexps);
|
||||||
|
auto c = matchFirst(str, regexp);
|
||||||
|
assert(c);
|
||||||
|
assert(c.whichPattern == 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -374,9 +374,15 @@ if (isSomeString!(S))
|
||||||
app.put("|");
|
app.put("|");
|
||||||
app.put("(?:");
|
app.put("(?:");
|
||||||
app.put(patterns[i]);
|
app.put(patterns[i]);
|
||||||
|
// terminator for the pattern
|
||||||
|
// to detect if the pattern unexpectedly ends
|
||||||
app.put("\\");
|
app.put("\\");
|
||||||
app.put(cast(dchar)(privateUseStart+i)); // special end marker
|
app.put(cast(dchar)(privateUseStart+i));
|
||||||
app.put(")");
|
app.put(")");
|
||||||
|
// another one to return correct whichPattern
|
||||||
|
// for all of potential alternatives in the patterns[i]
|
||||||
|
app.put("\\");
|
||||||
|
app.put(cast(dchar)(privateUseStart+i));
|
||||||
}
|
}
|
||||||
pat = app.data;
|
pat = app.data;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue