summaryrefslogtreecommitdiffstats
path: root/generic/tclRegexp.c
diff options
context:
space:
mode:
authorandy <andrew.m.goth@gmail.com>2016-11-25 07:31:46 (GMT)
committerandy <andrew.m.goth@gmail.com>2016-11-25 07:31:46 (GMT)
commita3572d2400fc9b189ceb5f6f2c929486d136ab05 (patch)
tree490d820debff6d8b19ebf40ac93bc4515ccefd59 /generic/tclRegexp.c
parent45f0dfd1a9fd6c3b5e3ca9a23da2cfedd364c1f7 (diff)
downloadtcl-a3572d2400fc9b189ceb5f6f2c929486d136ab05.zip
tcl-a3572d2400fc9b189ceb5f6f2c929486d136ab05.tar.gz
tcl-a3572d2400fc9b189ceb5f6f2c929486d136ab05.tar.bz2
Allow [array names -regexp] to use backreferences. This capability was broken by [71270e9141]. See also bug [1366683].
Diffstat (limited to 'generic/tclRegexp.c')
-rw-r--r--generic/tclRegexp.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/generic/tclRegexp.c b/generic/tclRegexp.c
index ea25d4b..eb23f72 100644
--- a/generic/tclRegexp.c
+++ b/generic/tclRegexp.c
@@ -502,9 +502,16 @@ Tcl_RegExpMatchObj(
{
Tcl_RegExp re;
- re = Tcl_GetRegExpFromObj(interp, patternObj,
- TCL_REG_ADVANCED | TCL_REG_NOSUB);
- if (re == NULL) {
+ /*
+ * For performance reasons, first try compiling the RE without support for
+ * subexpressions. On failure, try again without TCL_REG_NOSUB in case the
+ * RE has backreferences in it. Closely related to [Bug 1366683]. If this
+ * still fails, an error message will be left in the interpreter.
+ */
+
+ if (!(re = Tcl_GetRegExpFromObj(interp, patternObj,
+ TCL_REG_ADVANCED | TCL_REG_NOSUB))
+ && !(re = Tcl_GetRegExpFromObj(interp, patternObj, TCL_REG_ADVANCED))) {
return -1;
}
return Tcl_RegExpExecObj(interp, re, textObj, 0 /* offset */,