| Ticket UUID: | 3556218 | ||
| Title: | string match & glob: close-bracket in character set | ||
| Type: | Bug | Created on: | 2012-08-11 00:22:57 |
| Submitter: | avl42 | Assigned to: | dkf |
| Subsystem: | 18. Commands M-Z | Severity: | |
| Priority: | 5 Medium | Last modified: | 2026-10-19 17:43:27 |
| Status: | Open | Closed by: | |
| Resolution: | None | Closed on: | |
| Version: | 8.6.18, 9.0.5, 9.1.0 | ||
| Description: | ||||
As of now, it is not possible to include a close-bracket character in a bracketed set of allowed characters. [scan]'s format uses bracketed sets of allowed characters, too, and it *does* allow a close-bracket as first char. Having looked into the implementation of tcl's string-globbing, it seems that *before* entering that loop over the bracketed characters, an initial check for ']' in the pattern and in the string to be matched would be a really simple fix. Doing it that way, would even still allow a dash to be included verbatim, as well, by placing it right after the close-bracket. | ||||
| User Comments: | ||||
dkf added on 2012-08-13 06:19:51:
See also Bug 219233, for related issues. serhiy.storchaka added on 2026-10-19 17:43:27:
Still present in 8.6, 9.0 and 9.1: there is no way to include a closing bracket in a set. Backslash is not special inside a set, and {[]a]} never matches anything. The only workaround was a range ending in the closing bracket, which always includes other characters: the narrowest one, {[\-]]}, also matches a backslash. And such ranges are what [219233ffff] removes. Proposed fix for 9.1 in branch glob-bracket-posix, together with [219233ffff]: a closing bracket right after the opening one is a member of the set, as in POSIX and Python's fnmatch, so {[]a]} matches "]" or "a". Such patterns never matched before, so nothing that works changes. string.n now describes both rules. Test string-11.58. | ||||
