Overview
| Artifact ID: | 818f118fc5d48853635ceca01b581f5e0f57060d |
|---|---|
| Ticket: | 219122ffffffffffffffffffffffffffffffffff
regexp -all handles "^" incorrectly |
| User & Date: | nobody on 2000-10-26 01:11:05 |
Changes
- assignee changed to: "nobody"
- cmimetype changed to: "text/plain"
- comment changed to:
OriginalBugID: 6284 Bug Version: 8.4a1 SubmitDate: '2000-09-19' LastModified: '2000-09-19' Severity: MED Status: Released Submitter: techsupp ChangedBy: ericm OS: Linux-Red Hat OSVersion: Redhat 7.0beta FixedDate: '2000-09-19' FixedInVersion: 8.4a2 ClosedDate: '2000-10-25' Name: Mark Patton CustomShell: Moved a test to set a flag in the Comments: Since the regexp using "-start" works I checked the code and noticed that the TCL_REG_NOTBOL flag is only set when the "-start" flag is given and offset > 0. It should really be set any time when offset > 0 ie. when looping through a string with "-all". ReproducibleScript: % regexp -all -inline ^a aaaa a a a a % regexp -all -inline -start 1 ^a aaaa ObservedBehavior: I expected only one a to be matched in the first regexp because only one a is at the beginning of the string. Note that the second regexp correctly matches nothing. DesiredBehavior: The -all option should respect the "^" constraint and only match once. Patch: *** tclCmdMZ.c.origSun Sep 10 11:59:34 2000 --- tclCmdMZ.cMon Sep 11 20:50:55 2000 *************** *** 248,261 **** return TCL_OK; } - if (offset > 0) { - /* - * Add flag if using offset (string is part of a larger string), - * so that "^" won't match. - */ - eflags |= TCL_REG_NOTBOL; - } - objc -= 2; objv += 2; resultPtr = Tcl_GetObjResult(interp); --- 248,253 ---- *************** *** 289,294 **** --- 281,294 ---- */ while (1) { + if (offset > 0) { + /* + * Add flag if using offset (string is part of a larger string), + * so that "^" won't match. + */ + eflags |= TCL_REG_NOTBOL; + } + match = Tcl_RegExpExecObj(interp, regExpr, objPtr, offset /* offset */, numMatchesSaved, eflags); PatchFiles: tclCmdMZ.c Thanks for reporting this bug. I elected to fix it slightly differently than you did: *** tclCmdMZ.c 2000/09/06 18:31:36 1.29 --- tclCmdMZ.c 2000/09/20 01:32:56 *************** *** 433,438 **** --- 433,439 ---- } offset += info.matches[0].end; all++; + eflags |= TCL_REG_NOTBOL; if (offset >= stringLength) { break; } This fix avoids the additional "if" test each time through the while loop. We know that offset will be non-zero every time through the while loop after the first, so the "if (offset > 0)" test is redundant. Thanks for reporting and suggesting a fix! Eric Melski The Other Tcl Guy ericm at ajubasolutions.com Ajuba Solutions -- 09/19/2000 ericm - foundin changed to: "obsolete: 8.4a1"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- status changed to: "Open"
- submitter changed to: "nobody"
- subsystem changed to: "69. Other"
- title changed to: "regexp -all handles "^" incorrectly"
- type changed to: "Bug"