Tcl Source Code

View Ticket
Login
Ticket UUID: 1178541
Title: REG_BOSONLY incorrect with |
Type: Bug Created on: 2005-04-07 13:37:44
Submitter: wielemaker Assigned to: aku
Subsystem: 43. Regexp Severity: Minor
Priority: 5 Medium Last modified: 2026-10-11 08:46:45
Status: Open Closed by: nobody
Resolution: None Closed on:
Version: 8.6.18, 9.0.5, 9.1.0
Description:
Hi,

I've incorporated the Tcl regex code in my project
(www.swi-prolog.org) and found a bug in the regex
code.  I guess that will also affect Tcl.  I didn't
find a patch yet, I have some trouble sorting out the
internals.

In my app it shows as

?-send(regex('foo|bar'), match, 'xxx bar').

which succeeds!

Match (instead of search) sets REG_BOSONLY, but this causes
the regex to be read as \Afoo|bar rather than \A(foo|bar).

Using foo|\Abar, all works fine as well.

      Cheers --- Jan
User Comments:
wielemaker added on 2005-04-07 21:42:00:
Logged In: YES 
user_id=1222641

After a bit if hacking I came up with the following patch. 
Its not
tested very much, but it does run the fairly limited test
set I have.
Note that the lines may be shifted a bit as I made some more
modifications to interface the code with the rest of the
environment,

    Cheers --- Jan

wielemaker added on 2005-04-07 21:42:01:

File Added - 128932: x

tgl added on 2015-11-06 22:14:19:
The complained-of behavior certainly seems to be a bug, but I do not like Jan's proposed fix much --- it's taking an implementation that was a kluge to start with and making it even more messy.  I suggest the attached instead, which works by not generating arcs corresponding to the forbidden cases to begin with.

Another idea worth considering is to remove REG_BOSONLY altogether ... does anyone know if Expect still uses it?

serhiy.storchaka added on 2026-10-11 08:46:45:

Still the same in 8.6, 9.0 and 9.1.

Proposed fix in branch regexp-bosonly-alternatives: the patch by tgl below. With it, all alternatives are anchored, and the results agree with \A(?:re), also with TCL_REG_NOTBOL. Test reg-30.9.

Expect does not use TCL_REG_BOSONLY any more (it only passes TCL_REG_ADVANCED and TCL_REG_NOCASE); in Tcl itself only testregexp uses it. The flag is kept for other users of tclInt.h.


Attachments: