"subst" processes "return" incorrectly
Closed / Fixed219829ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-31 02:17:44
The command:
puts [subst {[return {}; should be invisible]}]
outputs nothing in Tcl8.0 as I would expect. But
it outputs "should be invisible]" in 8.3.0 and in
8.4a2.
In general, a "return" statement within [...] inside
a subst causes the scanning of text inside the [...]
to stop immediately, rather than continuing on to the
closing ']'. I do not have a fix at this time.
This comes up when using "subst" to embed TCL in
web pages (for example in tclhttpd). The work-
around is to do
[if 1 {...}]
in place of
[...]
hobbsplain2000-11-01 00:46:47
This seems to have cropped up specifically in 8.2 somewhere.
If I use 8.2b2, I get really weird results:
% info patch
8.2b2
% subst {[return {}; should be invisible]}
can't read "i": no such variable
% subst {[return {}; should be invisible]}
1o_pa
Whereas 8.2.3-8.4a has saner, but incorrect behavior:
% info patch
8.2.3
% subst {[return {}; should be invisible]}
should be invisible]
hobbsplain2000-11-02 04:45:26
Fixed with the following patch. There was varying behavior from 7.6 to 8.2 that (in 8.0+) was all broken in one way or another. The following allows for the best effort, keeping close compatability with 7.6.
cvs diff -bc generic/tclParse.c
Index: generic/tclParse.c
===================================================================
RCS file: /home/cvs/external/tcl/generic/tclParse.c,v
retrieving revision 1.13
diff -b -c -r1.13 tclParse.c
*** tclParse.c 1999/11/10 02:51:57 1.13
--- tclParse.c 2000/11/01 21:43:50
***************
*** 1456,1470 ****
Tcl_DecrRefCount(objv[i]);
}
if (gotParse) {
! p = parse.commandStart + parse.commandSize;
Tcl_FreeParse(&parse);
! if ((nested != 0) && (p > script) && (p[-1] == ']')) {
/*
* We get here in the special case where the TCL_BRACKET_TERM
! * flag was set in the interpreter and we reached a close
! * bracket in the script. Return immediately.
*/
iPtr->termOffset = (p - 1) - script;
} else {
iPtr->termOffset = p - script;
--- 1456,1506 ----
Tcl_DecrRefCount(objv[i]);
}
if (gotParse) {
! next = parse.commandStart + parse.commandSize;
! bytesLeft -= next - p;
! p = next;
Tcl_FreeParse(&parse);
!
! if ((nested != 0) && (p > script)) {
! char *nextCmd = NULL; /* pointer to start of next command */
!
/*
* We get here in the special case where the TCL_BRACKET_TERM
! * flag was set in the interpreter.
! *
! * At this point, we want to find the end of the script
! * (either end of script or the closing ']').
! */
!
! while ((p[-1] != ']') && bytesLeft) {
! if (Tcl_ParseCommand(NULL, p, bytesLeft, nested, &parse)
! != TCL_OK) {
! /*
! * We were looking for the ']' to close the script.
! * But if we find a syntax error, it is ok to quit
! * early since in that case we no longer need to know
! * where the ']' is (if there was one). We reset the
! * pointer to the start of the command that after the
! * one causing the return. -- hobbs
*/
+ p = (nextCmd == NULL) ? parse.commandStart : nextCmd;
+ break;
+ }
+
+ if (nextCmd == NULL) {
+ nextCmd = parse.commandStart;
+ }
+
+ /*
+ * Advance to the next command in the script.
+ */
+
+ next = parse.commandStart + parse.commandSize;
+ bytesLeft -= next - p;
+ p = next;
+ Tcl_FreeParse(&parse);
+ }
iPtr->termOffset = (p - 1) - script;
} else {
iPtr->termOffset = p - script;
dgp Ticket [219829ffff]: 4 changes
[History diff]2001-04-05 08:06:24
Log in (anonymous is fine) to add a comment.