diff options
| author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-09-21 12:55:59 (GMT) |
|---|---|---|
| committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-09-21 12:55:59 (GMT) |
| commit | 0f53e9d9697ee1bf84f6fdba09ec752711484f85 (patch) | |
| tree | 72f7aa4cfe58d05193183e02f20dac68dd5d800c | |
| parent | 9b0b59d046f223efca4855691ed4f476fa43b1b8 (diff) | |
| parent | 4590e2d12033ebf1ad82a2b46da552f0638b763a (diff) | |
| download | tcl-0f53e9d9697ee1bf84f6fdba09ec752711484f85.zip tcl-0f53e9d9697ee1bf84f6fdba09ec752711484f85.tar.gz tcl-0f53e9d9697ee1bf84f6fdba09ec752711484f85.tar.bz2 | |
Fix [c0bc269178]: switch -regexp -matchvar -indexvar broken when optional subexpression does not match
| -rw-r--r-- | generic/tclCmdMZ.c | 8 | ||||
| -rw-r--r-- | tests/switch.test | 7 |
2 files changed, 13 insertions, 2 deletions
diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index 3ff9947..53e12c5 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -3930,8 +3930,12 @@ TclNRSwitchObjCmd( if (matchVarObj != NULL) { Tcl_Obj *substringObj; - substringObj = Tcl_GetRange(stringObj, - info.matches[j].start, info.matches[j].end-1); + if (info.matches[j].end > 0) { + substringObj = Tcl_GetRange(stringObj, + info.matches[j].start, info.matches[j].end-1); + } else { + TclNewObj(substringObj); + } /* * Never fails; the object is always clean at this point. diff --git a/tests/switch.test b/tests/switch.test index 8ca049c..a7211cb 100644 --- a/tests/switch.test +++ b/tests/switch.test @@ -745,6 +745,13 @@ test switch-14.16 {switch -regexp compilation} { } }} } no +test switch-14.17 {switch -regexp bug [c0bc269178]} { + set result {} + switch -regexp -matchvar m -indexvar i ac { + {(a)(b)?(c)} {set result $m} + } + set result +} {ac a {} c} test switch-15.1 {coroutine safety of non-bytecoded switch} {*}{ -body { |
