Skip to content

Commit 7b12ad2

Browse files
committed
Bug [cb03e57a] - raise error on empty regexp if variable not resolvable
1 parent 992c832 commit 7b12ad2

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

generic/tclCompCmdsGR.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,14 +2007,11 @@ TclCompileRegexpCmd(
20072007
return TCL_ERROR;
20082008
}
20092009

2010-
if (len == 0) {
2011-
/*
2012-
* The semantics of regexp are always match on re == "".
2013-
*/
2014-
2015-
PushStringLiteral(envPtr, "1");
2016-
return TCL_OK;
2017-
}
2010+
/*
2011+
* Note: do not optimize for len == 0, as error should be generated
2012+
* at runtime if operand is not a resolvable variable.
2013+
* Bug https://core.tcl-lang.org/tcl/info/cb03e57a7b24d22c
2014+
*/
20182015

20192016
/*
20202017
* Attempt to convert pattern to glob. If successful, push the

tests/regexp.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,11 @@ test regexp-27.12 {regsub -command representation smash} {
11991199
set s {list (.+)}
12001200
regsub -command $s {list list} $s
12011201
} {(.+) {list list} list}
1202+
1203+
test regexp-28.1 {bug cb03e57a7b} -returnCodes error -body {
1204+
regexp {} $nosuchvar
1205+
} -result {can't read "nosuchvar": no such variable}
1206+
12021207

12031208
# cleanup
12041209
::tcltest::cleanupTests

0 commit comments

Comments
 (0)