Tcl Source Code

View Ticket
Login
2026-11-18
18:32 • Closed ticket [697b1bbfe3]: Incorrect argument handling by regexp plus 4 o... artifact: 5e808a5aa2 user: serhiy.storchaka
18:27 • Ticket [1902890fff] compiled regexp behaves differently status still Pending... artifact: b40148c895 user: serhiy.storchaka
18:27 • Ticket [697b1bbfe3] Incorrect argument handling by regexp status still Pen... artifact: 3afa410f3b user: serhiy.storchaka
18:21
Fix [697b1bbfe3] and [1902890fff]: Incorrect argument handling by [regexp] check-in: b0610ccd6f user: serhiy.storchaka tags: core-8-6-branch
17:42 • Pending ticket [697b1bbfe3]: Incorrect argument handling by regexp plus 5 ... artifact: 3e0e8a1136 user: jan.nijtmans
17:39
Fix [697b1bbfe3] and [1902890fff]: Incorrect argument handling by [regexp] check-in: 33b0599e53 user: jan.nijtmans tags: core-9-0-branch
2026-11-08
20:53 • Ticket [697b1bbfe3] Incorrect argument handling by regexp status still Ope... artifact: 15facf6005 user: dkf
2026-10-14
09:26
Fix [697b1bbfe3] and [1902890fff]: Incorrect argument handling by [regexp] check-in: 6e93204003 user: jan.nijtmans tags: trunk, main
2026-10-11
07:39 • Ticket [697b1bbfe3] Incorrect argument handling by regexp status still Ope... artifact: c78524a5f0 user: serhiy.storchaka
07:35
Fix [1902890]: compiled [regexp] did not treat an RE value starting with "-" as a switch, unlike the... closed check-in: 0b36adaf16 user: serhiy.storchaka tags: regexp-compile-runtime-switch
2026-10-10
21:12 • Ticket [697b1bbfe3] Incorrect argument handling by regexp status still Ope... artifact: cc6ba518d4 user: serhiy.storchaka
21:12 • Ticket [697b1bbfe3]: 3 changes artifact: ae26d49811 user: serhiy.storchaka
21:10
Fix cases #2 and #4 of [697b1bbfe3]: the bytecode compiler for [regexp] checked for a leading "-" on... closed check-in: a64804ce70 user: serhiy.storchaka tags: regexp-compile-dash-pattern
2022-09-18
11:30 • New ticket [697b1bbfe3] Incorrect argument handling by regexp. artifact: 834398468f user: erikleunissen

Ticket UUID: 697b1bbfe3387b8f777e55d4aba9a4e20833e8ed
Title: Incorrect argument handling by [regexp]
Type: Bug Created on: 2022-09-18 11:30:05
Submitter: erikleunissen Assigned to: jan.nijtmans
Subsystem: 43. Regexp Severity: Minor
Priority: 5 Medium Last modified: 2026-11-18 18:32:47
Status: Closed Closed by: serhiy.storchaka
Resolution: Fixed Closed on: 2026-11-18 18:32:47
Version: 8.6.18, 9.0.5, 9.1.0
Description:
Here are the results of six invocations of the "regexp" command.
They indicate incorrect argument handling.


% set str "a-z"
a-z
% regexp - $str; #1
bad option "-": must be -all, -about, -indices, -inline, -expanded, -line, -linestop, -lineanchor, -nocase, -start, or --
% regexp \- $str; #2
1
% regexp {-} $str; #3
bad option "-": must be -all, -about, -indices, -inline, -expanded, -line, -linestop, -lineanchor, -nocase, -start, or --
% regexp -\\ $str; #4
couldn't compile regular expression pattern: invalid escape \ sequence
% regexp \\- $str; #5
1
% set initstring "-"
-
% regexp $initstring $str; #6
1
%

This discussion thread at c.l.t. provides some clues:

    https://groups.google.com/g/comp.lang.tcl/c/pbqqj8tcIUk
User Comments:
serhiy.storchaka added on 2026-10-10 21:12:12:

Still the same in 8.6, 9.0 and 9.1. Cases #1, #3 and #5 are correct: an argument starting with "-" is taken as an option unless it follows --. #2 and #4 differ from the command only in compiled code: the bytecode compiler checked for a leading "-" only in words without backslashes, so \- and -\\ were compiled as patterns. #6 (a pattern in a variable) is the same problem as [1902890fff].

Proposed fix for #2 and #4 in branch regexp-compile-dash-pattern: the compiler checks the value of any word known at compile time, as for regsub, so both now give "bad option" as in #1. Tests regexpComp-24.12 to 24.15.


serhiy.storchaka added on 2026-10-11 07:39:52:

Proposed fix for case #6 in branch regexp-compile-runtime-switch, see [1902890fff].


jan.nijtmans added on 2026-11-18 17:42:21:

Fixed in [6e93204003|trunk] and core-9-0-branch

Many thanks!

Would be nice to backport this to 8.6.19 as well.


serhiy.storchaka added on 2026-11-18 18:27:58:

Backported to core-8-6-branch: [b0610ccd6f]. In 8.6, regexp \- a-z reports "bad option" instead of 9.0's "ambiguous option", compiled and uncompiled alike, so regexpComp-24.12 expects that.