From dc113d8f285f5b53a9fa035527abe05704027ab4 Mon Sep 17 00:00:00 2001 From: oehhar Date: Thu, 18 Aug 2022 20:16:05 +0000 Subject: TIP633 fconfigure -tolerantencoding: start command arguments --- generic/tclIO.c | 27 ++++++++++++++++++++++++++- generic/tclIO.h | 2 ++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/generic/tclIO.c b/generic/tclIO.c index 5313eed..4e3e41c 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -7905,7 +7905,20 @@ Tcl_GetChannelOption( return TCL_OK; } } - if (len == 0 || HaveOpt(1, "-translation")) { + if (len == 0 || HaveOpt(2, "-tolerantencoding")) { + if (len == 0) { + Tcl_DStringAppendElement(dsPtr, "-tolerantencoding"); + } + Tcl_DStringAppendElement(dsPtr, + (flags & CHANNEL_TOLERANT_ENCODING) ? "1" : "0"); + if (len > 0) { + return TCL_OK; + } + if (len > 0) { + return TCL_OK; + } + } + if (len == 0 || HaveOpt(2, "-translation")) { if (len == 0) { Tcl_DStringAppendElement(dsPtr, "-translation"); } @@ -8158,6 +8171,18 @@ Tcl_SetChannelOption( ResetFlag(statePtr, CHANNEL_EOF|CHANNEL_STICKY_EOF|CHANNEL_BLOCKED); statePtr->inputEncodingFlags &= ~TCL_ENCODING_END; return TCL_OK; + } else if (HaveOpt(2, "-tolerantencoding")) { + int newMode; + + if (Tcl_GetBoolean(interp, newValue, &newMode) == TCL_ERROR) { + return TCL_ERROR; + } + if (newMode) { + statePtr->flags |= CHANNEL_TOLERANT_ENCODING; + } else { + statePtr->flags &= ~CHANNEL_TOLERANT_ENCODING; + } + return TCL_OK; } else if (HaveOpt(1, "-translation")) { const char *readMode, *writeMode; diff --git a/generic/tclIO.h b/generic/tclIO.h index 54aa5af..1d63c0b 100644 --- a/generic/tclIO.h +++ b/generic/tclIO.h @@ -271,6 +271,8 @@ typedef struct ChannelState { * changes. */ #define CHANNEL_RAW_MODE (1<<16) /* When set, notes that the Raw API is * being used. */ +#define CHANNEL_TOLERANT_ENCODING (1<<17) /* set if option -tolerantencoding + * is set to 1 */ #define CHANNEL_INCLOSE (1<<19) /* Channel is currently being closed. * Its structures are still live and -- cgit v0.12 From 9a1e8d3202a29dcc11dc8c54e01a02e1f6565fd1 Mon Sep 17 00:00:00 2001 From: oehhar Date: Thu, 18 Aug 2022 20:20:10 +0000 Subject: Correct option shortcut value --- generic/tclIO.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generic/tclIO.c b/generic/tclIO.c index 4e3e41c..6d9798e 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -8183,7 +8183,7 @@ Tcl_SetChannelOption( statePtr->flags &= ~CHANNEL_TOLERANT_ENCODING; } return TCL_OK; - } else if (HaveOpt(1, "-translation")) { + } else if (HaveOpt(2, "-translation")) { const char *readMode, *writeMode; if (Tcl_SplitList(interp, newValue, &argc, &argv) == TCL_ERROR) { -- cgit v0.12 From 688186d7268b10d38b7e93cfa719208ebc1f96b2 Mon Sep 17 00:00:00 2001 From: oehhar Date: Thu, 25 Aug 2022 20:07:29 +0000 Subject: TIP633 fconfigure -tolerantencoding: set tolerant 8.7 default value. --- generic/tclIO.c | 14 +++++++++++--- generic/tclIO.h | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/generic/tclIO.c b/generic/tclIO.c index 6d9798e..cf96559 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -1703,6 +1703,14 @@ Tcl_CreateChannel( statePtr->outputEncodingFlags = TCL_ENCODING_START; /* + * Set encoding tolerant mode as default on 8.7.x and off on TCL9.x + */ + + #if TCL_MAJOR_VERSION < 9 + statePtr->flags |= CHANNEL_ENCODING_NOCOMPLAIN; + #endif + + /* * Set the channel up initially in AUTO input translation mode to accept * "\n", "\r" and "\r\n". Output translation mode is set to a platform * specific default value. The eofChar is set to 0 for both input and @@ -7910,7 +7918,7 @@ Tcl_GetChannelOption( Tcl_DStringAppendElement(dsPtr, "-tolerantencoding"); } Tcl_DStringAppendElement(dsPtr, - (flags & CHANNEL_TOLERANT_ENCODING) ? "1" : "0"); + (flags & CHANNEL_ENCODING_NOCOMPLAIN) ? "1" : "0"); if (len > 0) { return TCL_OK; } @@ -8178,9 +8186,9 @@ Tcl_SetChannelOption( return TCL_ERROR; } if (newMode) { - statePtr->flags |= CHANNEL_TOLERANT_ENCODING; + statePtr->flags |= CHANNEL_ENCODING_NOCOMPLAIN; } else { - statePtr->flags &= ~CHANNEL_TOLERANT_ENCODING; + statePtr->flags &= ~CHANNEL_ENCODING_NOCOMPLAIN; } return TCL_OK; } else if (HaveOpt(2, "-translation")) { diff --git a/generic/tclIO.h b/generic/tclIO.h index 1d63c0b..58e0c0f 100644 --- a/generic/tclIO.h +++ b/generic/tclIO.h @@ -271,7 +271,7 @@ typedef struct ChannelState { * changes. */ #define CHANNEL_RAW_MODE (1<<16) /* When set, notes that the Raw API is * being used. */ -#define CHANNEL_TOLERANT_ENCODING (1<<17) /* set if option -tolerantencoding +#define CHANNEL_ENCODING_NOCOMPLAIN (1<<17) /* set if option -tolerantencoding * is set to 1 */ #define CHANNEL_INCLOSE (1<<19) /* Channel is currently being closed. -- cgit v0.12 From 8ad68e4ae6be99da8761d19c3755707dd0f08f95 Mon Sep 17 00:00:00 2001 From: oehhar Date: Fri, 9 Sep 2022 17:09:10 +0000 Subject: TIP633: fconfigure -tolerantencoding: correct/add command interface tests --- tests/io.test | 15 +++++++++++++++ tests/ioCmd.test | 12 ++++++------ tests/socket.test | 2 +- tests/zlib.test | 4 ++-- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/tests/io.test b/tests/io.test index b6c4fb5..653c02b 100644 --- a/tests/io.test +++ b/tests/io.test @@ -8985,6 +8985,21 @@ test io-75.2 {unrepresentable character write passes and is replaced by ?} -setu removeFile io-75.2 } -returnCodes ok -result "A?" +test io-75.3 {check if -tolerantencoding option is saved} -setup { + set fn [makeFile {} io-75.3] + set f [open $fn w] +} -body { + # the following command gets in result error in TCL 9.0 + fconfigure $f -encoding iso8859-1 -tolerantencoding 0 + lappend res [fconfigure $f -tolerantencoding] + fconfigure $f -encoding iso8859-1 -tolerantencoding 1 + lappend res [fconfigure $f -tolerantencoding] +} -cleanup { + close $f + removeFile io-75.3 +} -returnCodes ok -result "0 1" + + # ### ### ### ######### ######### ######### # cleanup diff --git a/tests/ioCmd.test b/tests/ioCmd.test index dbca866..908ac5a 100644 --- a/tests/ioCmd.test +++ b/tests/ioCmd.test @@ -245,7 +245,7 @@ test iocmd-8.7 {fconfigure command} -setup { fconfigure $f1 } -cleanup { catch {close $f1} -} -result {-blocking 1 -buffering full -buffersize 4096 -encoding utf-16 -eofchar {} -translation lf} +} -result {-blocking 1 -buffering full -buffersize 4096 -encoding utf-16 -eofchar {} -tolerantencoding 1 -translation lf} test iocmd-8.8 {fconfigure command} -setup { file delete $path(test1) set x {} @@ -257,7 +257,7 @@ test iocmd-8.8 {fconfigure command} -setup { lappend x [fconfigure $f1] } -cleanup { catch {close $f1} -} -result {line {-blocking 1 -buffering line -buffersize 3030 -encoding utf-16 -eofchar {} -translation lf}} +} -result {line {-blocking 1 -buffering line -buffersize 3030 -encoding utf-16 -eofchar {} -tolerantencoding 1 -translation lf}} test iocmd-8.9 {fconfigure command} -setup { file delete $path(test1) } -body { @@ -267,7 +267,7 @@ test iocmd-8.9 {fconfigure command} -setup { fconfigure $f1 } -cleanup { catch {close $f1} -} -result {-blocking 1 -buffering none -buffersize 4040 -encoding binary -eofchar {} -translation lf} +} -result {-blocking 1 -buffering none -buffersize 4040 -encoding binary -eofchar {} -tolerantencoding 1 -translation lf} test iocmd-8.10 {fconfigure command} -returnCodes error -body { fconfigure a b } -result {can not find channel named "a"} @@ -1363,7 +1363,7 @@ test iocmd-25.1 {chan configure, cgetall, standard options} -match glob -body { close $c rename foo {} set res -} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -translation {auto *}}} +} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -tolerantencoding 1 -translation {auto *}}} test iocmd-25.2 {chan configure, cgetall, no options} -match glob -body { set res {} proc foo {args} {oninit cget cgetall; onfinal; track; return ""} @@ -1372,7 +1372,7 @@ test iocmd-25.2 {chan configure, cgetall, no options} -match glob -body { close $c rename foo {} set res -} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -translation {auto *}}} +} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -tolerantencoding 1 -translation {auto *}}} test iocmd-25.3 {chan configure, cgetall, regular result} -match glob -body { set res {} proc foo {args} { @@ -1384,7 +1384,7 @@ test iocmd-25.3 {chan configure, cgetall, regular result} -match glob -body { close $c rename foo {} set res -} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -translation {auto *} -bar foo -snarf x}} +} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -tolerantencoding 1 -translation {auto *} -bar foo -snarf x}} test iocmd-25.4 {chan configure, cgetall, bad result, list of uneven length} -match glob -body { set res {} proc foo {args} { diff --git a/tests/socket.test b/tests/socket.test index 4644e1d..c354f46 100644 --- a/tests/socket.test +++ b/tests/socket.test @@ -1071,7 +1071,7 @@ test socket_$af-7.3 {testing socket specific options} -constraints [list socket close $s update llength $l -} -result 14 +} -result 16 test socket_$af-7.4 {testing socket specific options} -constraints [list socket supported_$af] -setup { set timer [after 10000 "set x timed_out"] set l "" diff --git a/tests/zlib.test b/tests/zlib.test index 7de6d64..8c2d368 100644 --- a/tests/zlib.test +++ b/tests/zlib.test @@ -292,7 +292,7 @@ test zlib-8.6 {transformation and fconfigure} -setup { } -cleanup { catch {close $fd} removeFile $file -} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -translation lf} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -translation lf -checksum 1 -dictionary {}} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -translation lf}} +} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -tolerantencoding 1 -translation lf} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -tolerantencoding 1 -translation lf -checksum 1 -dictionary {}} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -tolerantencoding 1 -translation lf}} test zlib-8.7 {transformation and fconfigure} -setup { set file [makeFile {} test.gz] set fd [open $file wb] @@ -302,7 +302,7 @@ test zlib-8.7 {transformation and fconfigure} -setup { } -cleanup { catch {close $fd} removeFile $file -} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -translation lf} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -translation lf -checksum 0} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -translation lf}} +} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -tolerantencoding 1 -translation lf} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -tolerantencoding 1 -translation lf -checksum 0} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -tolerantencoding 1 -translation lf}} # Input is headers from fetching SPDY draft # Dictionary is that which is proposed _in_ SPDY draft set spdyHeaders "HTTP/1.0 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nX-Robots-Tag: noarchive\r\nLast-Modified: Tue, 05 Jun 2012 02:43:25 GMT\r\nETag: \"1338864205129|#public|0|en|||0\"\r\nExpires: Tue, 05 Jun 2012 16:17:11 GMT\r\nDate: Tue, 05 Jun 2012 16:17:06 GMT\r\nCache-Control: public, max-age=5\r\nX-Content-Type-Options: nosniff\r\nX-XSS-Protection: 1; mode=block\r\nServer: GSE\r\n" -- cgit v0.12 From 77334ba0ad75d22574c957a65fff91ea17e3bc8e Mon Sep 17 00:00:00 2001 From: oehhar Date: Sun, 11 Sep 2022 08:24:21 +0000 Subject: TIP633 fconfigure -strctencoding: TCL 9 branch: prepare test cases with -strictencoding 0 and 1 --- tests/io.test | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 74 insertions(+), 11 deletions(-) diff --git a/tests/io.test b/tests/io.test index f65e221..8ff3972 100644 --- a/tests/io.test +++ b/tests/io.test @@ -8952,9 +8952,7 @@ test io-74.1 {[104f2885bb] improper cache validity check} -setup { removeFile io-74.1 } -returnCodes error -match glob -result {can not find channel named "*"} -# Note: the following tests 75.1 to 75.3 are in preparation for TCL 9.0, where -# those should result in an error result -test io-75.1 {multibyte encoding error read results in raw bytes} -setup { +test io-75.1 {multibyte encoding error read results in raw bytes (-strictencoding 0)} -setup { set fn [makeFile {} io-75.1] set f [open $fn w+] fconfigure $f -encoding binary @@ -8963,24 +8961,29 @@ test io-75.1 {multibyte encoding error read results in raw bytes} -setup { puts -nonewline $f "A\xC0\x40" flush $f seek $f 0 - fconfigure $f -encoding utf-8 -buffering none -} -constraints knownBug -body { + fconfigure $f -encoding utf-8 -strictencoding 0 -buffering none +} -body { read $f } -cleanup { close $f removeFile io-75.1 -} -returnCodes error +} -returnCodes ok -result "A\xC0\x40" +# for TCL 9.0, the result is error -test io-75.2 {unrepresentable character write passes and is replaced by ?} -setup { +test io-75.2 {unrepresentable character write passes and is replaced by ? (-strictencoding 0)} -constraints deprecated -setup { set fn [makeFile {} io-75.2] set f [open $fn w+] - fconfigure $f -encoding iso8859-1 -} -constraints knownBug -body { + fconfigure $f -encoding iso8859-1 -strictencoding 0 +} -body { + # the following command gets in result error in TCL 9.0 puts -nonewline $f "A\u2022" + flush $f + seek $f 0 + read $f } -cleanup { close $f removeFile io-75.2 -} -returnCodes error +} -returnCodes ok -result "A?" # Incomplete sequence test. # This error may IMHO only be detected with the close. @@ -8992,15 +8995,75 @@ test io-75.3 {incomplete multibyte encoding read is ignored} -setup { puts -nonewline $f "A\xC0" flush $f seek $f 0 + fconfigure $f -encoding utf-8 -buffering none -strictencoding 0 +} -body { + set d [read $f] + close $f + set d +} -cleanup { + removeFile io-75.3 +} -returnCodes ok -result "A\xC0" + +test io-75.4 {multibyte encoding error read results in raw bytes (-strictencoding 1} -setup { + set fn [makeFile {} io-75.4] + set f [open $fn w+] + fconfigure $f -encoding binary + # In UTF-8, a byte 0xCx starts a multibyte sequence and must be followed + # by a byte > 0x7F. This is violated to get an invalid sequence. + puts -nonewline $f "A\xC0\x40" + flush $f + seek $f 0 + fconfigure $f -encoding utf-8 -buffering none +} -constraints knownBug -body { + read $f +} -cleanup { + close $f + removeFile io-75.4 +} -returnCodes error + +test io-75.5 {unrepresentable character write passes and is replaced by ? (-strictencoding 1} -setup { + set fn [makeFile {} io-75.5] + set f [open $fn w+] + fconfigure $f -encoding iso8859-1 +} -constraints knownBug -body { + puts -nonewline $f "A\u2022" +} -cleanup { + close $f + removeFile io-75.5 +} -returnCodes error + +# Incomplete sequence test. +# This error may IMHO only be detected with the close. +# But the read already returns the incomplete sequence. +test io-75.6 {incomplete multibyte encoding read is ignored (-strictencoding 1)} -setup { + set fn [makeFile {} io-75.6] + set f [open $fn w+] + fconfigure $f -encoding binary + puts -nonewline $f "A\xC0" + flush $f + seek $f 0 fconfigure $f -encoding utf-8 -buffering none } -constraints knownBug -body { set d [read $f] close $f set d } -cleanup { - removeFile io-75.3 + removeFile io-75.5 } -returnCodes error +test io-75.7 {check if -tolerantencoding option is saved} -setup { + set fn [makeFile {} io-75.7] + set f [open $fn w] +} -body { + fconfigure $f -encoding iso8859-1 -strictencoding 0 + lappend res [fconfigure $f -strictencoding] + fconfigure $f -encoding iso8859-1 -strictencoding 1 + lappend res [fconfigure $f -strictencoding] +} -cleanup { + close $f + removeFile io-75.7 +} -returnCodes ok -result "0 1" + # ### ### ### ######### ######### ######### # cleanup -- cgit v0.12 From 370f7dfa406329d5dfbf91ef4da3d647230ee99c Mon Sep 17 00:00:00 2001 From: oehhar Date: Sun, 11 Sep 2022 08:55:59 +0000 Subject: TIP633 fconfigure -strictencoding: change option name to "-strictencoding". --- generic/tclIO.c | 12 ++++++------ generic/tclIO.h | 4 ++-- tests/io.test | 14 -------------- tests/ioCmd.test | 12 ++++++------ tests/zlib.test | 4 ++-- 5 files changed, 16 insertions(+), 30 deletions(-) diff --git a/generic/tclIO.c b/generic/tclIO.c index cf96559..0f5f9c0 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -7913,12 +7913,12 @@ Tcl_GetChannelOption( return TCL_OK; } } - if (len == 0 || HaveOpt(2, "-tolerantencoding")) { + if (len == 0 || HaveOpt(2, "-strictencoding")) { if (len == 0) { - Tcl_DStringAppendElement(dsPtr, "-tolerantencoding"); + Tcl_DStringAppendElement(dsPtr, "-strictencoding"); } Tcl_DStringAppendElement(dsPtr, - (flags & CHANNEL_ENCODING_NOCOMPLAIN) ? "1" : "0"); + (flags & CHANNEL_ENCODING_NOCOMPLAIN) ? "0" : "1"); if (len > 0) { return TCL_OK; } @@ -8179,16 +8179,16 @@ Tcl_SetChannelOption( ResetFlag(statePtr, CHANNEL_EOF|CHANNEL_STICKY_EOF|CHANNEL_BLOCKED); statePtr->inputEncodingFlags &= ~TCL_ENCODING_END; return TCL_OK; - } else if (HaveOpt(2, "-tolerantencoding")) { + } else if (HaveOpt(2, "-strictencoding")) { int newMode; if (Tcl_GetBoolean(interp, newValue, &newMode) == TCL_ERROR) { return TCL_ERROR; } if (newMode) { - statePtr->flags |= CHANNEL_ENCODING_NOCOMPLAIN; - } else { statePtr->flags &= ~CHANNEL_ENCODING_NOCOMPLAIN; + } else { + statePtr->flags |= CHANNEL_ENCODING_NOCOMPLAIN; } return TCL_OK; } else if (HaveOpt(2, "-translation")) { diff --git a/generic/tclIO.h b/generic/tclIO.h index 58e0c0f..54ffe0e 100644 --- a/generic/tclIO.h +++ b/generic/tclIO.h @@ -271,8 +271,8 @@ typedef struct ChannelState { * changes. */ #define CHANNEL_RAW_MODE (1<<16) /* When set, notes that the Raw API is * being used. */ -#define CHANNEL_ENCODING_NOCOMPLAIN (1<<17) /* set if option -tolerantencoding - * is set to 1 */ +#define CHANNEL_ENCODING_NOCOMPLAIN (1<<17) /* set if option -strictencoding + * is set to 0 */ #define CHANNEL_INCLOSE (1<<19) /* Channel is currently being closed. * Its structures are still live and diff --git a/tests/io.test b/tests/io.test index adb5620..5c45918 100644 --- a/tests/io.test +++ b/tests/io.test @@ -9006,20 +9006,6 @@ test io-75.3 {incomplete multibyte encoding read is ignored} -setup { removeFile io-75.3 } -returnCodes ok -result "A\xC0" -test io-75.4 {check if -tolerantencoding option is saved} -setup { - set fn [makeFile {} io-75.4] - set f [open $fn w] -} -body { - # the following command gets in result error in TCL 9.0 - fconfigure $f -encoding iso8859-1 -tolerantencoding 0 - lappend res [fconfigure $f -tolerantencoding] - fconfigure $f -encoding iso8859-1 -tolerantencoding 1 - lappend res [fconfigure $f -tolerantencoding] -} -cleanup { - close $f - removeFile io-75.4 -} -returnCodes ok -result "0 1" - # ### ### ### ######### ######### ######### # cleanup diff --git a/tests/ioCmd.test b/tests/ioCmd.test index 908ac5a..178b54a 100644 --- a/tests/ioCmd.test +++ b/tests/ioCmd.test @@ -245,7 +245,7 @@ test iocmd-8.7 {fconfigure command} -setup { fconfigure $f1 } -cleanup { catch {close $f1} -} -result {-blocking 1 -buffering full -buffersize 4096 -encoding utf-16 -eofchar {} -tolerantencoding 1 -translation lf} +} -result {-blocking 1 -buffering full -buffersize 4096 -encoding utf-16 -eofchar {} -strictencoding 1 -translation lf} test iocmd-8.8 {fconfigure command} -setup { file delete $path(test1) set x {} @@ -257,7 +257,7 @@ test iocmd-8.8 {fconfigure command} -setup { lappend x [fconfigure $f1] } -cleanup { catch {close $f1} -} -result {line {-blocking 1 -buffering line -buffersize 3030 -encoding utf-16 -eofchar {} -tolerantencoding 1 -translation lf}} +} -result {line {-blocking 1 -buffering line -buffersize 3030 -encoding utf-16 -eofchar {} -strictencoding 1 -translation lf}} test iocmd-8.9 {fconfigure command} -setup { file delete $path(test1) } -body { @@ -267,7 +267,7 @@ test iocmd-8.9 {fconfigure command} -setup { fconfigure $f1 } -cleanup { catch {close $f1} -} -result {-blocking 1 -buffering none -buffersize 4040 -encoding binary -eofchar {} -tolerantencoding 1 -translation lf} +} -result {-blocking 1 -buffering none -buffersize 4040 -encoding binary -eofchar {} -strictencoding 1 -translation lf} test iocmd-8.10 {fconfigure command} -returnCodes error -body { fconfigure a b } -result {can not find channel named "a"} @@ -1363,7 +1363,7 @@ test iocmd-25.1 {chan configure, cgetall, standard options} -match glob -body { close $c rename foo {} set res -} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -tolerantencoding 1 -translation {auto *}}} +} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -strictencoding 1 -translation {auto *}}} test iocmd-25.2 {chan configure, cgetall, no options} -match glob -body { set res {} proc foo {args} {oninit cget cgetall; onfinal; track; return ""} @@ -1372,7 +1372,7 @@ test iocmd-25.2 {chan configure, cgetall, no options} -match glob -body { close $c rename foo {} set res -} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -tolerantencoding 1 -translation {auto *}}} +} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -strictencoding 1 -translation {auto *}}} test iocmd-25.3 {chan configure, cgetall, regular result} -match glob -body { set res {} proc foo {args} { @@ -1384,7 +1384,7 @@ test iocmd-25.3 {chan configure, cgetall, regular result} -match glob -body { close $c rename foo {} set res -} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -tolerantencoding 1 -translation {auto *} -bar foo -snarf x}} +} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -strictencoding 1 -translation {auto *} -bar foo -snarf x}} test iocmd-25.4 {chan configure, cgetall, bad result, list of uneven length} -match glob -body { set res {} proc foo {args} { diff --git a/tests/zlib.test b/tests/zlib.test index 8c2d368..f848b58 100644 --- a/tests/zlib.test +++ b/tests/zlib.test @@ -292,7 +292,7 @@ test zlib-8.6 {transformation and fconfigure} -setup { } -cleanup { catch {close $fd} removeFile $file -} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -tolerantencoding 1 -translation lf} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -tolerantencoding 1 -translation lf -checksum 1 -dictionary {}} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -tolerantencoding 1 -translation lf}} +} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 1 -translation lf} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 1 -translation lf -checksum 1 -dictionary {}} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 1 -translation lf}} test zlib-8.7 {transformation and fconfigure} -setup { set file [makeFile {} test.gz] set fd [open $file wb] @@ -302,7 +302,7 @@ test zlib-8.7 {transformation and fconfigure} -setup { } -cleanup { catch {close $fd} removeFile $file -} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -tolerantencoding 1 -translation lf} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -tolerantencoding 1 -translation lf -checksum 0} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -tolerantencoding 1 -translation lf}} +} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 1 -translation lf} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 1 -translation lf -checksum 0} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 1 -translation lf}} # Input is headers from fetching SPDY draft # Dictionary is that which is proposed _in_ SPDY draft set spdyHeaders "HTTP/1.0 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nX-Robots-Tag: noarchive\r\nLast-Modified: Tue, 05 Jun 2012 02:43:25 GMT\r\nETag: \"1338864205129|#public|0|en|||0\"\r\nExpires: Tue, 05 Jun 2012 16:17:11 GMT\r\nDate: Tue, 05 Jun 2012 16:17:06 GMT\r\nCache-Control: public, max-age=5\r\nX-Content-Type-Options: nosniff\r\nX-XSS-Protection: 1; mode=block\r\nServer: GSE\r\n" -- cgit v0.12 From 330bdbdecea1f151f8d1f1bdb7648ce6161b795e Mon Sep 17 00:00:00 2001 From: oehhar Date: Sun, 11 Sep 2022 09:27:10 +0000 Subject: TIP633 fconfigure -strictencoding: make only "-strictencoding 0" possible on TCL 8.7 --- generic/tclIO.c | 31 +++++++++++-------------------- generic/tclIO.h | 2 -- tests/ioCmd.test | 19 +++++++++++++------ tests/zlib.test | 4 ++-- 4 files changed, 26 insertions(+), 30 deletions(-) diff --git a/generic/tclIO.c b/generic/tclIO.c index 0f5f9c0..b801441 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -1703,14 +1703,6 @@ Tcl_CreateChannel( statePtr->outputEncodingFlags = TCL_ENCODING_START; /* - * Set encoding tolerant mode as default on 8.7.x and off on TCL9.x - */ - - #if TCL_MAJOR_VERSION < 9 - statePtr->flags |= CHANNEL_ENCODING_NOCOMPLAIN; - #endif - - /* * Set the channel up initially in AUTO input translation mode to accept * "\n", "\r" and "\r\n". Output translation mode is set to a platform * specific default value. The eofChar is set to 0 for both input and @@ -7913,20 +7905,16 @@ Tcl_GetChannelOption( return TCL_OK; } } - if (len == 0 || HaveOpt(2, "-strictencoding")) { + if (len == 0 || HaveOpt(1, "-strictencoding")) { if (len == 0) { Tcl_DStringAppendElement(dsPtr, "-strictencoding"); } - Tcl_DStringAppendElement(dsPtr, - (flags & CHANNEL_ENCODING_NOCOMPLAIN) ? "0" : "1"); - if (len > 0) { - return TCL_OK; - } + Tcl_DStringAppendElement(dsPtr,"0"); if (len > 0) { return TCL_OK; } } - if (len == 0 || HaveOpt(2, "-translation")) { + if (len == 0 || HaveOpt(1, "-translation")) { if (len == 0) { Tcl_DStringAppendElement(dsPtr, "-translation"); } @@ -8179,19 +8167,22 @@ Tcl_SetChannelOption( ResetFlag(statePtr, CHANNEL_EOF|CHANNEL_STICKY_EOF|CHANNEL_BLOCKED); statePtr->inputEncodingFlags &= ~TCL_ENCODING_END; return TCL_OK; - } else if (HaveOpt(2, "-strictencoding")) { + } else if (HaveOpt(1, "-strictencoding")) { int newMode; if (Tcl_GetBoolean(interp, newValue, &newMode) == TCL_ERROR) { return TCL_ERROR; } if (newMode) { - statePtr->flags &= ~CHANNEL_ENCODING_NOCOMPLAIN; - } else { - statePtr->flags |= CHANNEL_ENCODING_NOCOMPLAIN; + if (interp) { + Tcl_SetObjResult(interp, Tcl_NewStringObj( + "bad value for -strictencoding: only false allowed", + -1)); + } + return TCL_ERROR; } return TCL_OK; - } else if (HaveOpt(2, "-translation")) { + } else if (HaveOpt(1, "-translation")) { const char *readMode, *writeMode; if (Tcl_SplitList(interp, newValue, &argc, &argv) == TCL_ERROR) { diff --git a/generic/tclIO.h b/generic/tclIO.h index 54ffe0e..54aa5af 100644 --- a/generic/tclIO.h +++ b/generic/tclIO.h @@ -271,8 +271,6 @@ typedef struct ChannelState { * changes. */ #define CHANNEL_RAW_MODE (1<<16) /* When set, notes that the Raw API is * being used. */ -#define CHANNEL_ENCODING_NOCOMPLAIN (1<<17) /* set if option -strictencoding - * is set to 0 */ #define CHANNEL_INCLOSE (1<<19) /* Channel is currently being closed. * Its structures are still live and diff --git a/tests/ioCmd.test b/tests/ioCmd.test index 178b54a..ad4cd4e 100644 --- a/tests/ioCmd.test +++ b/tests/ioCmd.test @@ -245,7 +245,7 @@ test iocmd-8.7 {fconfigure command} -setup { fconfigure $f1 } -cleanup { catch {close $f1} -} -result {-blocking 1 -buffering full -buffersize 4096 -encoding utf-16 -eofchar {} -strictencoding 1 -translation lf} +} -result {-blocking 1 -buffering full -buffersize 4096 -encoding utf-16 -eofchar {} -strictencoding 0 -translation lf} test iocmd-8.8 {fconfigure command} -setup { file delete $path(test1) set x {} @@ -257,7 +257,7 @@ test iocmd-8.8 {fconfigure command} -setup { lappend x [fconfigure $f1] } -cleanup { catch {close $f1} -} -result {line {-blocking 1 -buffering line -buffersize 3030 -encoding utf-16 -eofchar {} -strictencoding 1 -translation lf}} +} -result {line {-blocking 1 -buffering line -buffersize 3030 -encoding utf-16 -eofchar {} -strictencoding 0 -translation lf}} test iocmd-8.9 {fconfigure command} -setup { file delete $path(test1) } -body { @@ -267,7 +267,7 @@ test iocmd-8.9 {fconfigure command} -setup { fconfigure $f1 } -cleanup { catch {close $f1} -} -result {-blocking 1 -buffering none -buffersize 4040 -encoding binary -eofchar {} -strictencoding 1 -translation lf} +} -result {-blocking 1 -buffering none -buffersize 4040 -encoding binary -eofchar {} -strictencoding 0 -translation lf} test iocmd-8.10 {fconfigure command} -returnCodes error -body { fconfigure a b } -result {can not find channel named "a"} @@ -369,6 +369,13 @@ test iocmd-8.20 {fconfigure command / win console channel} -constraints {nonPort } -returnCodes error -result [expectedOpts "-blah" {-inputmode}] # TODO: Test parsing of serial channel options (nonPortable, since requires an # open channel to work with). +test iocmd-8.21 {fconfigure command / -strictencoding 1 error} -setup { + # I don't know how else to open the console, but this is non-portable + set console stdin +} -body { + fconfigure $console -strictencoding 1 +} -returnCodes error -result "bad value for -strictencoding: only false allowed" + test iocmd-9.1 {eof command} { list [catch {eof} msg] $msg $::errorCode @@ -1363,7 +1370,7 @@ test iocmd-25.1 {chan configure, cgetall, standard options} -match glob -body { close $c rename foo {} set res -} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -strictencoding 1 -translation {auto *}}} +} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -strictencoding 0 -translation {auto *}}} test iocmd-25.2 {chan configure, cgetall, no options} -match glob -body { set res {} proc foo {args} {oninit cget cgetall; onfinal; track; return ""} @@ -1372,7 +1379,7 @@ test iocmd-25.2 {chan configure, cgetall, no options} -match glob -body { close $c rename foo {} set res -} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -strictencoding 1 -translation {auto *}}} +} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -strictencoding 0 -translation {auto *}}} test iocmd-25.3 {chan configure, cgetall, regular result} -match glob -body { set res {} proc foo {args} { @@ -1384,7 +1391,7 @@ test iocmd-25.3 {chan configure, cgetall, regular result} -match glob -body { close $c rename foo {} set res -} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -strictencoding 1 -translation {auto *} -bar foo -snarf x}} +} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -strictencoding 0 -translation {auto *} -bar foo -snarf x}} test iocmd-25.4 {chan configure, cgetall, bad result, list of uneven length} -match glob -body { set res {} proc foo {args} { diff --git a/tests/zlib.test b/tests/zlib.test index f848b58..a1c7aa4 100644 --- a/tests/zlib.test +++ b/tests/zlib.test @@ -292,7 +292,7 @@ test zlib-8.6 {transformation and fconfigure} -setup { } -cleanup { catch {close $fd} removeFile $file -} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 1 -translation lf} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 1 -translation lf -checksum 1 -dictionary {}} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 1 -translation lf}} +} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 0 -translation lf} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 0 -translation lf -checksum 1 -dictionary {}} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 0 -translation lf}} test zlib-8.7 {transformation and fconfigure} -setup { set file [makeFile {} test.gz] set fd [open $file wb] @@ -302,7 +302,7 @@ test zlib-8.7 {transformation and fconfigure} -setup { } -cleanup { catch {close $fd} removeFile $file -} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 1 -translation lf} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 1 -translation lf -checksum 0} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 1 -translation lf}} +} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 0 -translation lf} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 0 -translation lf -checksum 0} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 0 -translation lf}} # Input is headers from fetching SPDY draft # Dictionary is that which is proposed _in_ SPDY draft set spdyHeaders "HTTP/1.0 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nX-Robots-Tag: noarchive\r\nLast-Modified: Tue, 05 Jun 2012 02:43:25 GMT\r\nETag: \"1338864205129|#public|0|en|||0\"\r\nExpires: Tue, 05 Jun 2012 16:17:11 GMT\r\nDate: Tue, 05 Jun 2012 16:17:06 GMT\r\nCache-Control: public, max-age=5\r\nX-Content-Type-Options: nosniff\r\nX-XSS-Protection: 1; mode=block\r\nServer: GSE\r\n" -- cgit v0.12 From 14086d3b4aca32f2aa71c2799862593f2db4e0fd Mon Sep 17 00:00:00 2001 From: oehhar Date: Sun, 11 Sep 2022 09:55:09 +0000 Subject: TIP633 fconfigure -strictencoding: TCL 9 command line implementation --- generic/tclIO.c | 25 +++++++++++++++++++++++++ generic/tclIO.h | 2 ++ tests/io.test | 26 +++++++------------------- tests/ioCmd.test | 12 ++++++------ tests/zlib.test | 4 ++-- 5 files changed, 42 insertions(+), 27 deletions(-) diff --git a/generic/tclIO.c b/generic/tclIO.c index 5317e30..d8a9760 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -7869,6 +7869,19 @@ Tcl_GetChannelOption( return TCL_OK; } } + if (len == 0 || HaveOpt(1, "-strictencoding")) { + if (len == 0) { + Tcl_DStringAppendElement(dsPtr, "-strictencoding"); + } + Tcl_DStringAppendElement(dsPtr, + (flags & CHANNEL_ENCODING_NOCOMPLAIN) ? "0" : "1"); + if (len > 0) { + return TCL_OK; + } + if (len > 0) { + return TCL_OK; + } + } if (len == 0 || HaveOpt(1, "-translation")) { if (len == 0) { Tcl_DStringAppendElement(dsPtr, "-translation"); @@ -8132,6 +8145,18 @@ Tcl_SetChannelOption( ResetFlag(statePtr, CHANNEL_EOF|CHANNEL_STICKY_EOF|CHANNEL_BLOCKED); statePtr->inputEncodingFlags &= ~TCL_ENCODING_END; return TCL_OK; + } else if (HaveOpt(1, "-strictencoding")) { + int newMode; + + if (Tcl_GetBoolean(interp, newValue, &newMode) == TCL_ERROR) { + return TCL_ERROR; + } + if (newMode) { + statePtr->flags &= ~CHANNEL_ENCODING_NOCOMPLAIN; + } else { + statePtr->flags |= CHANNEL_ENCODING_NOCOMPLAIN; + } + return TCL_OK; } else if (HaveOpt(1, "-translation")) { const char *readMode, *writeMode; diff --git a/generic/tclIO.h b/generic/tclIO.h index ca6a0ac..a4128bc 100644 --- a/generic/tclIO.h +++ b/generic/tclIO.h @@ -271,6 +271,8 @@ typedef struct ChannelState { * changes. */ #define CHANNEL_RAW_MODE (1<<16) /* When set, notes that the Raw API is * being used. */ +#define CHANNEL_ENCODING_NOCOMPLAIN (1<<17) /* set if option -strictencoding + * is set to 0 */ #define CHANNEL_INCLOSE (1<<19) /* Channel is currently being closed. * Its structures are still live and diff --git a/tests/io.test b/tests/io.test index 8ff3972..eaec685 100644 --- a/tests/io.test +++ b/tests/io.test @@ -8952,6 +8952,7 @@ test io-74.1 {[104f2885bb] improper cache validity check} -setup { removeFile io-74.1 } -returnCodes error -match glob -result {can not find channel named "*"} + test io-75.1 {multibyte encoding error read results in raw bytes (-strictencoding 0)} -setup { set fn [makeFile {} io-75.1] set f [open $fn w+] @@ -8963,14 +8964,14 @@ test io-75.1 {multibyte encoding error read results in raw bytes (-strictencodin seek $f 0 fconfigure $f -encoding utf-8 -strictencoding 0 -buffering none } -body { - read $f + set d [read $f] + expr {$d eq "A\xC0\x40"} } -cleanup { close $f removeFile io-75.1 -} -returnCodes ok -result "A\xC0\x40" -# for TCL 9.0, the result is error +} -returnCodes ok -result 1 -test io-75.2 {unrepresentable character write passes and is replaced by ? (-strictencoding 0)} -constraints deprecated -setup { +test io-75.2 {unrepresentable character write passes and is replaced by ? (-strictencoding 0)} -setup { set fn [makeFile {} io-75.2] set f [open $fn w+] fconfigure $f -encoding iso8859-1 -strictencoding 0 @@ -9025,7 +9026,7 @@ test io-75.5 {unrepresentable character write passes and is replaced by ? (-stri set fn [makeFile {} io-75.5] set f [open $fn w+] fconfigure $f -encoding iso8859-1 -} -constraints knownBug -body { +} -body { puts -nonewline $f "A\u2022" } -cleanup { close $f @@ -9043,7 +9044,7 @@ test io-75.6 {incomplete multibyte encoding read is ignored (-strictencoding 1)} flush $f seek $f 0 fconfigure $f -encoding utf-8 -buffering none -} -constraints knownBug -body { +} -body { set d [read $f] close $f set d @@ -9051,19 +9052,6 @@ test io-75.6 {incomplete multibyte encoding read is ignored (-strictencoding 1)} removeFile io-75.5 } -returnCodes error -test io-75.7 {check if -tolerantencoding option is saved} -setup { - set fn [makeFile {} io-75.7] - set f [open $fn w] -} -body { - fconfigure $f -encoding iso8859-1 -strictencoding 0 - lappend res [fconfigure $f -strictencoding] - fconfigure $f -encoding iso8859-1 -strictencoding 1 - lappend res [fconfigure $f -strictencoding] -} -cleanup { - close $f - removeFile io-75.7 -} -returnCodes ok -result "0 1" - # ### ### ### ######### ######### ######### # cleanup diff --git a/tests/ioCmd.test b/tests/ioCmd.test index dbca866..178b54a 100644 --- a/tests/ioCmd.test +++ b/tests/ioCmd.test @@ -245,7 +245,7 @@ test iocmd-8.7 {fconfigure command} -setup { fconfigure $f1 } -cleanup { catch {close $f1} -} -result {-blocking 1 -buffering full -buffersize 4096 -encoding utf-16 -eofchar {} -translation lf} +} -result {-blocking 1 -buffering full -buffersize 4096 -encoding utf-16 -eofchar {} -strictencoding 1 -translation lf} test iocmd-8.8 {fconfigure command} -setup { file delete $path(test1) set x {} @@ -257,7 +257,7 @@ test iocmd-8.8 {fconfigure command} -setup { lappend x [fconfigure $f1] } -cleanup { catch {close $f1} -} -result {line {-blocking 1 -buffering line -buffersize 3030 -encoding utf-16 -eofchar {} -translation lf}} +} -result {line {-blocking 1 -buffering line -buffersize 3030 -encoding utf-16 -eofchar {} -strictencoding 1 -translation lf}} test iocmd-8.9 {fconfigure command} -setup { file delete $path(test1) } -body { @@ -267,7 +267,7 @@ test iocmd-8.9 {fconfigure command} -setup { fconfigure $f1 } -cleanup { catch {close $f1} -} -result {-blocking 1 -buffering none -buffersize 4040 -encoding binary -eofchar {} -translation lf} +} -result {-blocking 1 -buffering none -buffersize 4040 -encoding binary -eofchar {} -strictencoding 1 -translation lf} test iocmd-8.10 {fconfigure command} -returnCodes error -body { fconfigure a b } -result {can not find channel named "a"} @@ -1363,7 +1363,7 @@ test iocmd-25.1 {chan configure, cgetall, standard options} -match glob -body { close $c rename foo {} set res -} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -translation {auto *}}} +} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -strictencoding 1 -translation {auto *}}} test iocmd-25.2 {chan configure, cgetall, no options} -match glob -body { set res {} proc foo {args} {oninit cget cgetall; onfinal; track; return ""} @@ -1372,7 +1372,7 @@ test iocmd-25.2 {chan configure, cgetall, no options} -match glob -body { close $c rename foo {} set res -} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -translation {auto *}}} +} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -strictencoding 1 -translation {auto *}}} test iocmd-25.3 {chan configure, cgetall, regular result} -match glob -body { set res {} proc foo {args} { @@ -1384,7 +1384,7 @@ test iocmd-25.3 {chan configure, cgetall, regular result} -match glob -body { close $c rename foo {} set res -} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -translation {auto *} -bar foo -snarf x}} +} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -strictencoding 1 -translation {auto *} -bar foo -snarf x}} test iocmd-25.4 {chan configure, cgetall, bad result, list of uneven length} -match glob -body { set res {} proc foo {args} { diff --git a/tests/zlib.test b/tests/zlib.test index 7de6d64..f848b58 100644 --- a/tests/zlib.test +++ b/tests/zlib.test @@ -292,7 +292,7 @@ test zlib-8.6 {transformation and fconfigure} -setup { } -cleanup { catch {close $fd} removeFile $file -} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -translation lf} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -translation lf -checksum 1 -dictionary {}} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -translation lf}} +} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 1 -translation lf} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 1 -translation lf -checksum 1 -dictionary {}} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 1 -translation lf}} test zlib-8.7 {transformation and fconfigure} -setup { set file [makeFile {} test.gz] set fd [open $file wb] @@ -302,7 +302,7 @@ test zlib-8.7 {transformation and fconfigure} -setup { } -cleanup { catch {close $fd} removeFile $file -} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -translation lf} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -translation lf -checksum 0} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -translation lf}} +} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 1 -translation lf} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 1 -translation lf -checksum 0} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 1 -translation lf}} # Input is headers from fetching SPDY draft # Dictionary is that which is proposed _in_ SPDY draft set spdyHeaders "HTTP/1.0 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nX-Robots-Tag: noarchive\r\nLast-Modified: Tue, 05 Jun 2012 02:43:25 GMT\r\nETag: \"1338864205129|#public|0|en|||0\"\r\nExpires: Tue, 05 Jun 2012 16:17:11 GMT\r\nDate: Tue, 05 Jun 2012 16:17:06 GMT\r\nCache-Control: public, max-age=5\r\nX-Content-Type-Options: nosniff\r\nX-XSS-Protection: 1; mode=block\r\nServer: GSE\r\n" -- cgit v0.12 From f5846ef8f5f21d1aad31894ecee56c0c5cd5c3c1 Mon Sep 17 00:00:00 2001 From: oehhar Date: Mon, 12 Sep 2022 10:47:30 +0000 Subject: TIP633 fconfigure -strictencoding: implement write -strictencoding 0. --- generic/tclIO.c | 10 ++++++++++ tests/io.test | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/generic/tclIO.c b/generic/tclIO.c index 37bef84..4715954 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -4345,6 +4345,16 @@ Write( } dst = InsertPoint(bufPtr); dstLen = SpaceLeft(bufPtr); + + /* + * Transfer encoding strict option to the encoding flags + */ + + if (statePtr->flags & CHANNEL_ENCODING_NOCOMPLAIN) { + statePtr->outputEncodingFlags |= TCL_ENCODING_NOCOMPLAIN; + } else { + statePtr->outputEncodingFlags &= ~TCL_ENCODING_NOCOMPLAIN; + } result = Tcl_UtfToExternal(NULL, encoding, src, srcLimit, statePtr->outputEncodingFlags, diff --git a/tests/io.test b/tests/io.test index aeec781..dbb74f0 100644 --- a/tests/io.test +++ b/tests/io.test @@ -9014,7 +9014,7 @@ test io-75.4 {multibyte encoding error read results in raw bytes (-strictencodin flush $f seek $f 0 fconfigure $f -encoding utf-8 -buffering none -} -constraints knownBug -body { +} -body { read $f } -cleanup { close $f -- cgit v0.12 From c36fa478b248c2d1444e72ff0a27edc1fddbb208 Mon Sep 17 00:00:00 2001 From: oehhar Date: Mon, 12 Sep 2022 10:59:44 +0000 Subject: TIP633 fconfigure -strictencoding: move transfer over the loop. Adapt test suite to use hex results to prevent blocking on console output. --- generic/tclIO.c | 20 ++++++++++---------- tests/io.test | 10 ++++++---- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/generic/tclIO.c b/generic/tclIO.c index 4715954..c2f6add 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -4308,6 +4308,16 @@ Write( } /* + * Transfer encoding strict option to the encoding flags + */ + + if (statePtr->flags & CHANNEL_ENCODING_NOCOMPLAIN) { + statePtr->outputEncodingFlags |= TCL_ENCODING_NOCOMPLAIN; + } else { + statePtr->outputEncodingFlags &= ~TCL_ENCODING_NOCOMPLAIN; + } + + /* * Write the terminated escape sequence even if srcLen is 0. */ @@ -4346,16 +4356,6 @@ Write( dst = InsertPoint(bufPtr); dstLen = SpaceLeft(bufPtr); - /* - * Transfer encoding strict option to the encoding flags - */ - - if (statePtr->flags & CHANNEL_ENCODING_NOCOMPLAIN) { - statePtr->outputEncodingFlags |= TCL_ENCODING_NOCOMPLAIN; - } else { - statePtr->outputEncodingFlags &= ~TCL_ENCODING_NOCOMPLAIN; - } - result = Tcl_UtfToExternal(NULL, encoding, src, srcLimit, statePtr->outputEncodingFlags, &statePtr->outputEncodingState, dst, diff --git a/tests/io.test b/tests/io.test index dbb74f0..479695d 100644 --- a/tests/io.test +++ b/tests/io.test @@ -8964,11 +8964,12 @@ test io-75.1 {multibyte encoding error read results in raw bytes (-strictencodin fconfigure $f -encoding utf-8 -strictencoding 0 -buffering none } -body { set d [read $f] - expr {$d eq "A\xC0\x40"} + binary scan $d H* hd + set hd } -cleanup { close $f removeFile io-75.1 -} -returnCodes ok -result 1 +} -returnCodes ok -result "41C040" test io-75.2 {unrepresentable character write passes and is replaced by ? (-strictencoding 0)} -setup { set fn [makeFile {} io-75.2] @@ -8999,10 +9000,11 @@ test io-75.3 {incomplete multibyte encoding read is ignored} -setup { } -body { set d [read $f] close $f - set d + binary scan $d H* hd + set hd } -cleanup { removeFile io-75.3 -} -returnCodes ok -result "A\xC0" +} -returnCodes ok -result "41C0" test io-75.4 {multibyte encoding error read results in raw bytes (-strictencoding 1} -setup { set fn [makeFile {} io-75.4] -- cgit v0.12 From 9d536c3831e542752097c755a299643a06782298 Mon Sep 17 00:00:00 2001 From: oehhar Date: Mon, 19 Sep 2022 17:40:28 +0000 Subject: TIP633 fconfigure -nocomplainencoding (TCL9): replace "-strictencoding 0" by "-nocomplainencoding 1". --- generic/tclIO.c | 15 ++++++--------- generic/tclIO.h | 4 ++-- tests/io.test | 20 ++++++++++---------- tests/ioCmd.test | 12 ++++++------ tests/zlib.test | 4 ++-- 5 files changed, 26 insertions(+), 29 deletions(-) diff --git a/generic/tclIO.c b/generic/tclIO.c index c06ca5a..00327cb 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -7928,15 +7928,12 @@ Tcl_GetChannelOption( return TCL_OK; } } - if (len == 0 || HaveOpt(1, "-strictencoding")) { + if (len == 0 || HaveOpt(1, "-nocomplainencoding")) { if (len == 0) { - Tcl_DStringAppendElement(dsPtr, "-strictencoding"); + Tcl_DStringAppendElement(dsPtr, "-nocomplainencoding"); } Tcl_DStringAppendElement(dsPtr, - (flags & CHANNEL_ENCODING_NOCOMPLAIN) ? "0" : "1"); - if (len > 0) { - return TCL_OK; - } + (flags & CHANNEL_ENCODING_NOCOMPLAIN) ? "1" : "0"); if (len > 0) { return TCL_OK; } @@ -8204,16 +8201,16 @@ Tcl_SetChannelOption( ResetFlag(statePtr, CHANNEL_EOF|CHANNEL_STICKY_EOF|CHANNEL_BLOCKED); statePtr->inputEncodingFlags &= ~TCL_ENCODING_END; return TCL_OK; - } else if (HaveOpt(1, "-strictencoding")) { + } else if (HaveOpt(1, "-nocomplainencoding")) { int newMode; if (Tcl_GetBoolean(interp, newValue, &newMode) == TCL_ERROR) { return TCL_ERROR; } if (newMode) { - statePtr->flags &= ~CHANNEL_ENCODING_NOCOMPLAIN; - } else { statePtr->flags |= CHANNEL_ENCODING_NOCOMPLAIN; + } else { + statePtr->flags &= ~CHANNEL_ENCODING_NOCOMPLAIN; } return TCL_OK; } else if (HaveOpt(1, "-translation")) { diff --git a/generic/tclIO.h b/generic/tclIO.h index a4128bc..532dd62 100644 --- a/generic/tclIO.h +++ b/generic/tclIO.h @@ -271,8 +271,8 @@ typedef struct ChannelState { * changes. */ #define CHANNEL_RAW_MODE (1<<16) /* When set, notes that the Raw API is * being used. */ -#define CHANNEL_ENCODING_NOCOMPLAIN (1<<17) /* set if option -strictencoding - * is set to 0 */ +#define CHANNEL_ENCODING_NOCOMPLAIN (1<<17) /* set if option + * -nocomplainencoding is set to 1 */ #define CHANNEL_INCLOSE (1<<19) /* Channel is currently being closed. * Its structures are still live and diff --git a/tests/io.test b/tests/io.test index b606c3e..dc61466 100644 --- a/tests/io.test +++ b/tests/io.test @@ -8952,7 +8952,7 @@ test io-74.1 {[104f2885bb] improper cache validity check} -setup { removeFile io-74.1 } -returnCodes error -match glob -result {can not find channel named "*"} -test io-75.1 {multibyte encoding error read results in raw bytes (-strictencoding 0)} -setup { +test io-75.1 {multibyte encoding error read results in raw bytes (-nocomplainencoding 1)} -setup { set fn [makeFile {} io-75.1] set f [open $fn w+] fconfigure $f -encoding binary @@ -8961,7 +8961,7 @@ test io-75.1 {multibyte encoding error read results in raw bytes (-strictencodin puts -nonewline $f "A\xC0\x40" flush $f seek $f 0 - fconfigure $f -encoding utf-8 -strictencoding 0 -buffering none + fconfigure $f -encoding utf-8 -nocomplainencoding 1 -buffering none } -body { set d [read $f] binary scan $d H* hd @@ -8971,10 +8971,10 @@ test io-75.1 {multibyte encoding error read results in raw bytes (-strictencodin removeFile io-75.1 } -result "41c040" -test io-75.2 {unrepresentable character write passes and is replaced by ? (-strictencoding 0)} -setup { +test io-75.2 {unrepresentable character write passes and is replaced by ? (-nocomplainencoding 1)} -setup { set fn [makeFile {} io-75.2] set f [open $fn w+] - fconfigure $f -encoding iso8859-1 -strictencoding 0 + fconfigure $f -encoding iso8859-1 -nocomplainencoding 1 } -body { puts -nonewline $f "A\u2022" flush $f @@ -8988,14 +8988,14 @@ test io-75.2 {unrepresentable character write passes and is replaced by ? (-stri # Incomplete sequence test. # This error may IMHO only be detected with the close. # But the read already returns the incomplete sequence. -test io-75.3 {incomplete multibyte encoding read is ignored (-strictencoding 0)} -setup { +test io-75.3 {incomplete multibyte encoding read is ignored (-nocomplainencoding 1)} -setup { set fn [makeFile {} io-75.3] set f [open $fn w+] fconfigure $f -encoding binary puts -nonewline $f "A\xC0" flush $f seek $f 0 - fconfigure $f -encoding utf-8 -buffering none -strictencoding 0 + fconfigure $f -encoding utf-8 -buffering none -nocomplainencoding 1 } -body { set d [read $f] close $f @@ -9007,7 +9007,7 @@ test io-75.3 {incomplete multibyte encoding read is ignored (-strictencoding 0)} # As utf-8 has a special treatment in multi-byte decoding, also test another # one. -test io-75.4 {shiftjis encoding error read results in raw bytes (-strictencoding 0)} -setup { +test io-75.4 {shiftjis encoding error read results in raw bytes (-nocomplainencoding 1)} -setup { set fn [makeFile {} io-75.4] set f [open $fn w+] fconfigure $f -encoding binary @@ -9016,7 +9016,7 @@ test io-75.4 {shiftjis encoding error read results in raw bytes (-strictencoding puts -nonewline $f "A\x81\xFFA" flush $f seek $f 0 - fconfigure $f -encoding shiftjis -buffering none -eofchar "" -translation lf -strictencoding 0 + fconfigure $f -encoding shiftjis -buffering none -eofchar "" -translation lf -nocomplainencoding 1 } -body { set d [read $f] binary scan $d H* hd @@ -9026,7 +9026,7 @@ test io-75.4 {shiftjis encoding error read results in raw bytes (-strictencoding removeFile io-75.4 } -result "4181ff41" -test io-75.5 {incomplete shiftjis encoding read is ignored (-strictencoding 0)} -setup { +test io-75.5 {incomplete shiftjis encoding read is ignored (-nocomplainencoding 1)} -setup { set fn [makeFile {} io-75.5] set f [open $fn w+] fconfigure $f -encoding binary @@ -9034,7 +9034,7 @@ test io-75.5 {incomplete shiftjis encoding read is ignored (-strictencoding 0)} puts -nonewline $f "A\x81" flush $f seek $f 0 - fconfigure $f -encoding utf-8 -buffering none -eofchar "" -translation lf -strictencoding 0 + fconfigure $f -encoding utf-8 -buffering none -eofchar "" -translation lf -nocomplainencoding 1 } -body { set d [read $f] close $f diff --git a/tests/ioCmd.test b/tests/ioCmd.test index 178b54a..92e96a2 100644 --- a/tests/ioCmd.test +++ b/tests/ioCmd.test @@ -245,7 +245,7 @@ test iocmd-8.7 {fconfigure command} -setup { fconfigure $f1 } -cleanup { catch {close $f1} -} -result {-blocking 1 -buffering full -buffersize 4096 -encoding utf-16 -eofchar {} -strictencoding 1 -translation lf} +} -result {-blocking 1 -buffering full -buffersize 4096 -encoding utf-16 -eofchar {} -nocomplainencoding 0 -translation lf} test iocmd-8.8 {fconfigure command} -setup { file delete $path(test1) set x {} @@ -257,7 +257,7 @@ test iocmd-8.8 {fconfigure command} -setup { lappend x [fconfigure $f1] } -cleanup { catch {close $f1} -} -result {line {-blocking 1 -buffering line -buffersize 3030 -encoding utf-16 -eofchar {} -strictencoding 1 -translation lf}} +} -result {line {-blocking 1 -buffering line -buffersize 3030 -encoding utf-16 -eofchar {} -nocomplainencoding 0 -translation lf}} test iocmd-8.9 {fconfigure command} -setup { file delete $path(test1) } -body { @@ -267,7 +267,7 @@ test iocmd-8.9 {fconfigure command} -setup { fconfigure $f1 } -cleanup { catch {close $f1} -} -result {-blocking 1 -buffering none -buffersize 4040 -encoding binary -eofchar {} -strictencoding 1 -translation lf} +} -result {-blocking 1 -buffering none -buffersize 4040 -encoding binary -eofchar {} -nocomplainencoding 0 -translation lf} test iocmd-8.10 {fconfigure command} -returnCodes error -body { fconfigure a b } -result {can not find channel named "a"} @@ -1363,7 +1363,7 @@ test iocmd-25.1 {chan configure, cgetall, standard options} -match glob -body { close $c rename foo {} set res -} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -strictencoding 1 -translation {auto *}}} +} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -nocomplainencoding 0 -translation {auto *}}} test iocmd-25.2 {chan configure, cgetall, no options} -match glob -body { set res {} proc foo {args} {oninit cget cgetall; onfinal; track; return ""} @@ -1372,7 +1372,7 @@ test iocmd-25.2 {chan configure, cgetall, no options} -match glob -body { close $c rename foo {} set res -} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -strictencoding 1 -translation {auto *}}} +} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -nocomplainencoding 0 -translation {auto *}}} test iocmd-25.3 {chan configure, cgetall, regular result} -match glob -body { set res {} proc foo {args} { @@ -1384,7 +1384,7 @@ test iocmd-25.3 {chan configure, cgetall, regular result} -match glob -body { close $c rename foo {} set res -} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -strictencoding 1 -translation {auto *} -bar foo -snarf x}} +} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -nocomplainencoding 0 -translation {auto *} -bar foo -snarf x}} test iocmd-25.4 {chan configure, cgetall, bad result, list of uneven length} -match glob -body { set res {} proc foo {args} { diff --git a/tests/zlib.test b/tests/zlib.test index f848b58..d20011f 100644 --- a/tests/zlib.test +++ b/tests/zlib.test @@ -292,7 +292,7 @@ test zlib-8.6 {transformation and fconfigure} -setup { } -cleanup { catch {close $fd} removeFile $file -} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 1 -translation lf} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 1 -translation lf -checksum 1 -dictionary {}} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 1 -translation lf}} +} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -nocomplainencoding 0 -translation lf} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -nocomplainencoding 0 -translation lf -checksum 1 -dictionary {}} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -nocomplainencoding 0 -translation lf}} test zlib-8.7 {transformation and fconfigure} -setup { set file [makeFile {} test.gz] set fd [open $file wb] @@ -302,7 +302,7 @@ test zlib-8.7 {transformation and fconfigure} -setup { } -cleanup { catch {close $fd} removeFile $file -} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 1 -translation lf} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 1 -translation lf -checksum 0} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 1 -translation lf}} +} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -nocomplainencoding 0 -translation lf} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -nocomplainencoding 0 -translation lf -checksum 0} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -nocomplainencoding 0 -translation lf}} # Input is headers from fetching SPDY draft # Dictionary is that which is proposed _in_ SPDY draft set spdyHeaders "HTTP/1.0 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nX-Robots-Tag: noarchive\r\nLast-Modified: Tue, 05 Jun 2012 02:43:25 GMT\r\nETag: \"1338864205129|#public|0|en|||0\"\r\nExpires: Tue, 05 Jun 2012 16:17:11 GMT\r\nDate: Tue, 05 Jun 2012 16:17:06 GMT\r\nCache-Control: public, max-age=5\r\nX-Content-Type-Options: nosniff\r\nX-XSS-Protection: 1; mode=block\r\nServer: GSE\r\n" -- cgit v0.12 From 5d066cf1694f50526815d3b96301e4cf7f3007fd Mon Sep 17 00:00:00 2001 From: oehhar Date: Mon, 19 Sep 2022 17:45:10 +0000 Subject: TIP633 fconfigure -nocomplainencoding (TCL8.7): replace "-strictencoding 0" by "-nocomplainencoding 1". --- generic/tclIO.c | 12 ++++++------ tests/ioCmd.test | 18 +++++++++--------- tests/zlib.test | 4 ++-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/generic/tclIO.c b/generic/tclIO.c index 71ad637..3c1d4b0 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -7923,11 +7923,11 @@ Tcl_GetChannelOption( return TCL_OK; } } - if (len == 0 || HaveOpt(1, "-strictencoding")) { + if (len == 0 || HaveOpt(1, "-nocomplainencoding")) { if (len == 0) { - Tcl_DStringAppendElement(dsPtr, "-strictencoding"); + Tcl_DStringAppendElement(dsPtr, "-nocomplainencoding"); } - Tcl_DStringAppendElement(dsPtr,"0"); + Tcl_DStringAppendElement(dsPtr,"1"); if (len > 0) { return TCL_OK; } @@ -8185,16 +8185,16 @@ Tcl_SetChannelOption( ResetFlag(statePtr, CHANNEL_EOF|CHANNEL_STICKY_EOF|CHANNEL_BLOCKED); statePtr->inputEncodingFlags &= ~TCL_ENCODING_END; return TCL_OK; - } else if (HaveOpt(1, "-strictencoding")) { + } else if (HaveOpt(1, "-nocomplainencoding")) { int newMode; if (Tcl_GetBoolean(interp, newValue, &newMode) == TCL_ERROR) { return TCL_ERROR; } - if (newMode) { + if (!newMode) { if (interp) { Tcl_SetObjResult(interp, Tcl_NewStringObj( - "bad value for -strictencoding: only false allowed", + "bad value for -nocomplainencoding: only true allowed", -1)); } return TCL_ERROR; diff --git a/tests/ioCmd.test b/tests/ioCmd.test index ad4cd4e..0af12ce 100644 --- a/tests/ioCmd.test +++ b/tests/ioCmd.test @@ -245,7 +245,7 @@ test iocmd-8.7 {fconfigure command} -setup { fconfigure $f1 } -cleanup { catch {close $f1} -} -result {-blocking 1 -buffering full -buffersize 4096 -encoding utf-16 -eofchar {} -strictencoding 0 -translation lf} +} -result {-blocking 1 -buffering full -buffersize 4096 -encoding utf-16 -eofchar {} -nocomplainencoding 1 -translation lf} test iocmd-8.8 {fconfigure command} -setup { file delete $path(test1) set x {} @@ -257,7 +257,7 @@ test iocmd-8.8 {fconfigure command} -setup { lappend x [fconfigure $f1] } -cleanup { catch {close $f1} -} -result {line {-blocking 1 -buffering line -buffersize 3030 -encoding utf-16 -eofchar {} -strictencoding 0 -translation lf}} +} -result {line {-blocking 1 -buffering line -buffersize 3030 -encoding utf-16 -eofchar {} -nocomplainencoding 1 -translation lf}} test iocmd-8.9 {fconfigure command} -setup { file delete $path(test1) } -body { @@ -267,7 +267,7 @@ test iocmd-8.9 {fconfigure command} -setup { fconfigure $f1 } -cleanup { catch {close $f1} -} -result {-blocking 1 -buffering none -buffersize 4040 -encoding binary -eofchar {} -strictencoding 0 -translation lf} +} -result {-blocking 1 -buffering none -buffersize 4040 -encoding binary -eofchar {} -nocomplainencoding 1 -translation lf} test iocmd-8.10 {fconfigure command} -returnCodes error -body { fconfigure a b } -result {can not find channel named "a"} @@ -369,12 +369,12 @@ test iocmd-8.20 {fconfigure command / win console channel} -constraints {nonPort } -returnCodes error -result [expectedOpts "-blah" {-inputmode}] # TODO: Test parsing of serial channel options (nonPortable, since requires an # open channel to work with). -test iocmd-8.21 {fconfigure command / -strictencoding 1 error} -setup { +test iocmd-8.21 {fconfigure command / -nocomplainencoding 0 error} -setup { # I don't know how else to open the console, but this is non-portable set console stdin } -body { - fconfigure $console -strictencoding 1 -} -returnCodes error -result "bad value for -strictencoding: only false allowed" + fconfigure $console -nocomplainencoding 0 +} -returnCodes error -result "bad value for -nocomplainencoding: only true allowed" test iocmd-9.1 {eof command} { @@ -1370,7 +1370,7 @@ test iocmd-25.1 {chan configure, cgetall, standard options} -match glob -body { close $c rename foo {} set res -} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -strictencoding 0 -translation {auto *}}} +} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -nocomplainencoding 1 -translation {auto *}}} test iocmd-25.2 {chan configure, cgetall, no options} -match glob -body { set res {} proc foo {args} {oninit cget cgetall; onfinal; track; return ""} @@ -1379,7 +1379,7 @@ test iocmd-25.2 {chan configure, cgetall, no options} -match glob -body { close $c rename foo {} set res -} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -strictencoding 0 -translation {auto *}}} +} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -nocomplainencoding 1 -translation {auto *}}} test iocmd-25.3 {chan configure, cgetall, regular result} -match glob -body { set res {} proc foo {args} { @@ -1391,7 +1391,7 @@ test iocmd-25.3 {chan configure, cgetall, regular result} -match glob -body { close $c rename foo {} set res -} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -strictencoding 0 -translation {auto *} -bar foo -snarf x}} +} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -nocomplainencoding 1 -translation {auto *} -bar foo -snarf x}} test iocmd-25.4 {chan configure, cgetall, bad result, list of uneven length} -match glob -body { set res {} proc foo {args} { diff --git a/tests/zlib.test b/tests/zlib.test index a1c7aa4..6d71a81 100644 --- a/tests/zlib.test +++ b/tests/zlib.test @@ -292,7 +292,7 @@ test zlib-8.6 {transformation and fconfigure} -setup { } -cleanup { catch {close $fd} removeFile $file -} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 0 -translation lf} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 0 -translation lf -checksum 1 -dictionary {}} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 0 -translation lf}} +} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -nocomplainencoding 1 -translation lf} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -nocomplainencoding 1 -translation lf -checksum 1 -dictionary {}} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -nocomplainencoding 1 -translation lf}} test zlib-8.7 {transformation and fconfigure} -setup { set file [makeFile {} test.gz] set fd [open $file wb] @@ -302,7 +302,7 @@ test zlib-8.7 {transformation and fconfigure} -setup { } -cleanup { catch {close $fd} removeFile $file -} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 0 -translation lf} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 0 -translation lf -checksum 0} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -strictencoding 0 -translation lf}} +} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -nocomplainencoding 1 -translation lf} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -nocomplainencoding 1 -translation lf -checksum 0} {-blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -nocomplainencoding 1 -translation lf}} # Input is headers from fetching SPDY draft # Dictionary is that which is proposed _in_ SPDY draft set spdyHeaders "HTTP/1.0 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nX-Robots-Tag: noarchive\r\nLast-Modified: Tue, 05 Jun 2012 02:43:25 GMT\r\nETag: \"1338864205129|#public|0|en|||0\"\r\nExpires: Tue, 05 Jun 2012 16:17:11 GMT\r\nDate: Tue, 05 Jun 2012 16:17:06 GMT\r\nCache-Control: public, max-age=5\r\nX-Content-Type-Options: nosniff\r\nX-XSS-Protection: 1; mode=block\r\nServer: GSE\r\n" -- cgit v0.12 From d00000e8162adf60a7f52d474d430d0cf3cfab6c Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 22 Sep 2022 10:56:56 +0000 Subject: fix testcase --- tests/socket.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/socket.test b/tests/socket.test index 4644e1d..c354f46 100644 --- a/tests/socket.test +++ b/tests/socket.test @@ -1071,7 +1071,7 @@ test socket_$af-7.3 {testing socket specific options} -constraints [list socket close $s update llength $l -} -result 14 +} -result 16 test socket_$af-7.4 {testing socket specific options} -constraints [list socket supported_$af] -setup { set timer [after 10000 "set x timed_out"] set l "" -- cgit v0.12 From 5e4013330a16bddc87cd9179fce996982e333f20 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sat, 8 Oct 2022 00:10:13 +0000 Subject: -nocomplainencoding and -strictencoding are incompatible --- generic/tclIO.c | 23 +++++++++++++++++++++-- generic/tclIO.h | 2 ++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/generic/tclIO.c b/generic/tclIO.c index 85067f2..ca12d63 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -8009,7 +8009,8 @@ Tcl_GetChannelOption( if (len == 0) { Tcl_DStringAppendElement(dsPtr, "-nocomplainencoding"); } - Tcl_DStringAppendElement(dsPtr,"1"); + Tcl_DStringAppendElement(dsPtr, + (flags & CHANNEL_ENCODING_STRICT) ? "0" : "1"); if (len > 0) { return TCL_OK; } @@ -8283,7 +8284,17 @@ Tcl_SetChannelOption( if (Tcl_GetBoolean(interp, newValue, &newMode) == TCL_ERROR) { return TCL_ERROR; } - if (!newMode) { + if (newMode) { + if (statePtr->flags & CHANNEL_ENCODING_STRICT) { + if (interp) { + Tcl_SetObjResult(interp, Tcl_NewStringObj( + "-nocomplainencoding cannot be used with -strictencoding", + -1)); + } + return TCL_ERROR; + } + statePtr->flags |= CHANNEL_ENCODING_NOCOMPLAIN; + } else { if (interp) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "bad value for -nocomplainencoding: only true allowed", @@ -8299,6 +8310,14 @@ Tcl_SetChannelOption( return TCL_ERROR; } if (newMode) { + if (statePtr->flags & CHANNEL_ENCODING_NOCOMPLAIN) { + if (interp) { + Tcl_SetObjResult(interp, Tcl_NewStringObj( + "-strictencoding cannot be used with -nocomplainencoding", + -1)); + } + return TCL_ERROR; + } statePtr->flags |= CHANNEL_ENCODING_STRICT; } return TCL_OK; diff --git a/generic/tclIO.h b/generic/tclIO.h index b86dc1d..e8d2736 100644 --- a/generic/tclIO.h +++ b/generic/tclIO.h @@ -273,6 +273,8 @@ typedef struct ChannelState { * changes. */ #define CHANNEL_RAW_MODE (1<<16) /* When set, notes that the Raw API is * being used. */ +#define CHANNEL_ENCODING_NOCOMPLAIN (1<<17) /* set if option + * -nocomplaincoding is set to 1 */ #define CHANNEL_ENCODING_STRICT (1<<18) /* set if option * -strictencoding is set to 1 */ #define CHANNEL_INCLOSE (1<<19) /* Channel is currently being closed. -- cgit v0.12