|
2026-11-27
| ||
| 10:05 | • Ticket [219233ffff] string match oddity when - is the last char status still... artifact: 887898646d user: jan.nijtmans | |
|
2026-11-26
| ||
| 17:25 | • Ticket [219233ffff]: 3 changes artifact: edd9a13297 user: serhiy.storchaka | |
|
2026-10-19
| ||
| 17:56 | • Ticket [219233ffff]: 4 changes artifact: 1940dcb665 user: dgp | |
| 17:43 | • Ticket [3556218fff] string match & glob: close-bracket in character set ... artifact: fb9c71b0b9 user: serhiy.storchaka | |
| 17:43 | • Ticket [219233ffff] string match oddity when - is the last char status still... artifact: 3230c841bf user: serhiy.storchaka | |
| 17:38 | Fix [219233ffff] and [3556218fff]: in glob patterns ([string match], [glob], [lsearch -glob], [switc... check-in: 7ca44862f9 user: serhiy.storchaka tags: glob-bracket-posix | |
|
2018-05-07
| ||
| 22:03 | • Ticket [219233ffff] string match oddity when - is the last char status still... artifact: 044389336d user: sebres | |
| 16:21 | • Ticket [219233ffff]: 3 changes artifact: f0e1b306aa user: dgp | |
| 16:19 | • Ticket [219233ffff]: 8 changes artifact: 4ae03ebd5e user: dgp | |
|
2010-11-18
| ||
| 16:52 | • Ticket [219233ffff]: 4 changes artifact: c455066ad5 user: gneumann | |
|
2007-06-14
| ||
| 21:50 | • Ticket [219233ffff]: 4 changes artifact: f1b062ad37 user: dkf | |
| 21:00 | • Ticket [219233ffff]: 4 changes artifact: ac4fd569d8 user: matzek | |
| 20:56 | • Ticket [219233ffff]: 4 changes artifact: 9129f1297b user: matzek | |
|
2004-10-04
| ||
| 20:59 | • Ticket [219233ffff]: 1 change artifact: 09bea83268 user: dkf | |
|
2003-11-24
| ||
| 23:17 | • Ticket [219233ffff]: 4 changes artifact: 8855f8c3d8 user: dkf | |
|
2003-11-23
| ||
| 15:20 | • Ticket [219233ffff]: 4 changes artifact: cd95aef196 user: lupylucke | |
|
2001-03-17
| ||
| 03:57 | • Ticket [219233ffff]: 6 changes artifact: ba04fa04b4 user: dkf | |
|
2001-02-23
| ||
| 17:24 | • Ticket [219233ffff]: 4 changes artifact: 2b71110c1e user: dkf | |
|
2001-02-15
| ||
| 23:32 | • Ticket [219233ffff]: 5 changes artifact: 5377bc8f83 user: dkf | |
|
2001-02-07
| ||
| 23:02 | • Ticket [219233ffff]: 1 change artifact: 58b17dd6ea user: dkf | |
|
2000-11-24
| ||
| 20:18 | • Ticket [219233ffff]: 5 changes artifact: 4b48081319 user: dkf | |
| 18:35 | • Ticket [219233ffff]: 4 changes artifact: a12dfca596 user: dkf | |
|
2000-10-26
| ||
| 05:03 | • New ticket [219233ffff]. artifact: ab4f2a0c49 user: nobody | |
string match oddity when - is the last char
OriginalBugID: 4438 Bug
Version: 8.3
SubmitDate: '2000-03-21'
LastModified: '2000-04-03'
Severity: MED
Status: Assigned
Submitter: techsupp
ChangedBy: hobbs
OS: Windows 95
OSVersion: OSR2
FixedDate: '2000-10-25'
ClosedDate: '2000-10-25'
Name:
Keith Lea
ReproducibleScript:
% string match {[a-z0-9_/-]} \\
1
% string match {[a-z0-9_/]} \\
0
It's accidently interp'ing the "/-]" as "/-]]", taking last
] as ] endrange and ] endblock.
-- 04/03/2000 hobbs
This needs to be fixed in Tcl_String(Case)Match in tclUtil.c,
but wait until 8.4 just in case someone was counting on the
previous perverse behavior.
-- 04/03/2000 hobbs
fb9c71b0b9Ticket [3556218fff] string match & glob: close-bracket in character set status still Open with 4 other changes ticket2026-10-19 17:43:277ca44862f9Fix [219233ffff] and [3556218fff]: in glob patterns ([string match], [glob], [lsearch -glob], [switch -glob]), a "-" right before the closing bracket of a set now is a literal, and a closing bracket right after the opening one is a member of the set, as in POSIX. Before, such a "-" started a range up to the closing bracket, and a set starting with a closing bracket never matched. Only for 9.1: patterns that relied on a range ending in the closing bracket change meaning. check-in2026-10-19 17:38:04
Hmm. The problem seems to be that the first pattern is actually malformed by the rules of [string match], but there is no way to indicate this. I suppose the correct way of dealing with this is to decide that we were not really matching a range after all, but that's not very good at all. Either that, or we state that a malformed pattern matches nothing at all. Hmm. On successful matching of a range, should we really back up a character at the unexpected end of string , or should we fail at that point?
Improved detection of bug: % sstring match \[a-] ] 1 % string match \[a-]x ]x 0
Apparently, the way [string match] handles syntactically invalid patterns is by failing to match anything at all. It's not entirely clear to me that this is an optimal strategy...
See Patch #103932 https://sourceforge.net/patch/?func=detailpatch&patch_id=103932&group_id=10894
Logged In: YES user_id=79902 This behaviour won't be changed before 9.0 Any fixes that *are* done must be applied to code in both tclUtil.c and tclUtf.c
Logged In: YES
user_id=915599
I encountered a problem with `string match' too. I suppouse
it is, finally, the same bug: it is possible to match a [ in
a character set quoting int with \. Thits should work with ]
too, but it doesn't!
% string match {[\[]} {[}
1
% string match {[\]]} {]}
0
Logged In: YES
user_id=79902
Backslashes aren't special inside the square-bracket term,
so the first match doesn't match what you are expecting and
the second match isn't looking for what you think it is:
% set str \\
\
% string match {[\[]} $str
1
% set str {\]}
\]
% string match {[\]]} $str
1
The glob-matching engine used by [string match] isn't very
smart... :^( Consider using regular expressions instead.
Logged In: YES
user_id=330806
Originator: NO
Hi!
I add another example to the list:
% string match {*[.-]*} "2.1-Beta"
0
% string match {*[-.]*} "2.1-Beta"
1
% string match {*[.-]*} "Beta-2.1"
1
% string match {*[-.]*} "Beta-2.1"
1
If this is not going to be fixed soon, I suggest to at least document this behavior. Could be enough to just add the hyphen to the list of characters that need to be escaped...
kind regards
-- Matthias Kraft
Logged In: YES user_id=330806 Originator: NO I forgot to mention that the example below is taken from a recent Tcl interpreter (8.4.14)...
Logged In: YES user_id=79902 Originator: NO Comments below indicate "wait until 9.0", this being a strategy that was mainly from Jeff.
i was hit by apparently the same problem.
% string match {[-.]} -
1
% string match {[.-]} -
0
# even worse
% string match {[.-]} A
1
This is certainly unexpected behavior and should be at least documented.
"Wait until 9.0" is no longer a blockage. This should be fixed at least on the trunk, if not on earlier branches too.
If someone wants to pursue a "refactor first, then fix" strategy, I can accept that.
If the behavior like below is acceptable for you, I can do a back-porting from my own branches (I assume it's relative easy):
% string match {[.-B} A
invalid match pattern: brackets [] not balanced
Otherwise, I would like to know how exactly it must be then "fixed" (after the possible refactoring)...
E.g. another variant of the "fix" can be:
% string match {[.-B} A
0
% string match {[.-B} \[.-A
0
% string match {[.-B} \[.-B
1
Quasi by unbalanced brackets the pattern {[.-B} will be equivalent to the {\[.-B}
Anyway, current implementation is definitely wrong:
% string match {[.-B} A
1
should result either to an error or to 0.
Still present in 8.6, 9.0 and 9.1. Proposed fix for 9.1 in branch glob-bracket-posix, on top of glob-match-linear (the matcher change for [a4a7f2abd3]): in all four matchers, a - right before the closing bracket is a literal, as in POSIX and Python's fnmatch. So {[.-]} matches only "." and "-", and {*[.-]*} matches "2.1-Beta". Test string-11.57; util-5.40, 5.41, 5.43 and 5.44 tested the old behaviour and are changed. Unbalanced brackets ({[.-B}) are not changed.
Alert that if this change is accepted it will require bold labels of POTENTIAL INCOMPATIBILITY in the release notes. I'm unsettled by changing the functioning of RE processing in order to "fix" a "bug", most especially one that has survived for 25 years and more. Would help to have more people examine the impact.
Agreed, it is an incompatibility, so it is proposed for 9.1 only. But the current behaviour is hardly useful: {[.-]} is the range "." to "]", which matches "/", digits and upper-case letters, but not "-", and {[]a]} never matches. POSIX, glibc fnmatch, Python fnmatch, bash, dash and SQLite GLOB all treat a "-" before "]" as literal and a "]" first in a set as a member. Should this go through a TIP?
I would be OK putting this in 9.1, with a small 'potential incompatibility' in the release notes. It's too small for a TIP, and - actually - a bugfix