Skip to content

Commit cba5fec

Browse files
authored
Merge pull request #5705 from MartinNowak/merge_stable
Merge remote-tracking branch 'upstream/stable' into merge_stable merged-on-behalf-of: Jack Stouffer <[email protected]>
2 parents c648bca + 8667632 commit cba5fec

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

std/regex/internal/tests.d

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,3 +1106,15 @@ alias Sequence(int B, int E) = staticIota!(B, E);
11061106
auto e = collectException!RegexException(regex(q"<[^]>"));
11071107
assert(e.msg.canFind("no operand for '^'"), e.msg);
11081108
}
1109+
1110+
// bugzilla 17673
1111+
@safe unittest
1112+
{
1113+
string str = `<">`;
1114+
string[] regexps = ["abc", "\"|x"];
1115+
auto regexp = regex(regexps);
1116+
auto c = matchFirst(str, regexp);
1117+
assert(c);
1118+
assert(c.whichPattern == 2);
1119+
}
1120+

std/regex/package.d

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,15 @@ if (isSomeString!(S))
374374
app.put("|");
375375
app.put("(?:");
376376
app.put(patterns[i]);
377+
// terminator for the pattern
378+
// to detect if the pattern unexpectedly ends
377379
app.put("\\");
378-
app.put(cast(dchar)(privateUseStart+i)); // special end marker
380+
app.put(cast(dchar)(privateUseStart+i));
379381
app.put(")");
382+
// another one to return correct whichPattern
383+
// for all of potential alternatives in the patterns[i]
384+
app.put("\\");
385+
app.put(cast(dchar)(privateUseStart+i));
380386
}
381387
pat = app.data;
382388
}

0 commit comments

Comments
 (0)