From a6c24e9c1a78da2ae9a5d5e6a110f26da40ac143 Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Thu, 7 May 2020 09:21:23 +1000 Subject: lsearch, switch: fix -regexp case with option-like pattern If the pattern begins with -, the internal invocation of regexp will treat the pattern as an option. Fix this by adding -- to the internal invocation of regexp. Fixes #154 Reported-by: Barry Arthur Signed-off-by: Steve Bennett --- tests/jim.test | 9 +++++++++ tests/lsearch.test | 8 ++++++++ 2 files changed, 17 insertions(+) (limited to 'tests') diff --git a/tests/jim.test b/tests/jim.test index 121e909..eaef8aa 100644 --- a/tests/jim.test +++ b/tests/jim.test @@ -2500,6 +2500,15 @@ test switch-3.7 {-exact vs. -glob vs. -regexp} { list [catch {switch -foo a b c} msg] $msg } {1 {bad option "-foo": must be -exact, -glob, -regexp, -command procname or --}} +test switch-3.8 {switch -regexp with option-like pattern} regexp { + switch -regexp -- -def { + -abc {concat first} + -def {concat second} + -ghi {concat third} + default {concat none} + } +} second + test switch-4.1 {error in executed command} { list [catch {switch a a {error "Just a test"} default {expr 1}} msg] \ $msg diff --git a/tests/lsearch.test b/tests/lsearch.test index 1eb6607..ff1342a 100644 --- a/tests/lsearch.test +++ b/tests/lsearch.test @@ -72,6 +72,14 @@ test lsearch-2.9 {search modes, -nocase} { lsearch -nocase -glob {b.x ^bc xy bcx} B* } 0 +test lsearch-2.10 {regexp with option-looking pattern} regexp { + lsearch -regexp {-abc -def -ghi} -def +} 1 + +test lsearch-2.11 {regexp with option-looking pattern, -nocase} regexp { + lsearch -nocase -regexp {-abc -def -ghi} -DEF +} 1 + test lsearch-3.1 {lsearch errors} { list [catch lsearch msg] } {1} -- cgit v1.1