You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tcl.apache.org by mx...@apache.org on 2026/07/02 23:48:13 UTC

(tcl-rivet) branch master updated: complete utf-8 test suite, add -encoding option to ::rivet::parse

This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tcl-rivet.git


The following commit(s) were added to refs/heads/master by this push:
     new 73e322d  complete utf-8 test suite, add -encoding option to ::rivet::parse
73e322d is described below

commit 73e322dcc53d01d958442c650f0da9311b6abac0
Author: Massimo Manghi <mx...@apache.org>
AuthorDate: Fri Jul 3 01:48:07 2026 +0200

    complete utf-8 test suite, add -encoding option to ::rivet::parse
---
 ChangeLog                       | 44 ++++++++++++++++++++++++++++++++++++
 doc/xml/commands.xml            | 13 +++++++++++
 src/mod_rivet_ng/TclWebapache.c | 14 ++++++++++++
 src/mod_rivet_ng/rivetCore.c    | 50 +++++++++++++++++++++++++++++++++++------
 src/parser/rivetParser.c        | 19 +++++++++++++++-
 src/parser/rivetParser.h        |  2 ++
 tests/README                    |  7 ++++++
 tests/apachetest/apachetest.tcl |  4 ++--
 tests/bailout.test              |  9 ++++----
 tests/exit.tcl                  |  5 ++---
 tests/get.rvt                   |  4 ++--
 tests/headers.test              | 10 +++------
 tests/hello.rvt                 |  4 ++--
 tests/hello.test                |  4 ++--
 tests/include.html              |  2 +-
 tests/include.test              |  3 ++-
 tests/inspect.test              | 13 +++++++----
 tests/parse.rvt                 |  4 ++--
 tests/parse.test                | 42 +++++++++++++++++++++++++++++-----
 tests/parsepackage.test         |  8 +++----
 tests/parsestring.rvt           |  4 ++--
 tests/post.rvt                  |  4 ++--
 tests/post.test                 | 12 +++++-----
 tests/rivet.test                | 10 ++++-----
 tests/runtests.tcl              | 15 +++++--------
 tests/tclfile.tcl               |  2 +-
 tests/tclfile.test              |  2 +-
 27 files changed, 235 insertions(+), 75 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index dd9a45f..879f00d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,47 @@
+• 2026-07-03 Massimo Manghi <mx...@apache.org>
+  	* src/mod_rivet_ng/TclWebapache.c: Configure the Tcl output channel
+  	from the response charset for every request.
+  	* src/mod_rivet_ng/rivetCore.c: Add -encoding support to
+  	::rivet::parse and include the selected encoding in parser cache keys.
+  	* src/parser/rivetParser.c: Add encoding-aware template loading while
+  	preserving the existing default system-encoding behavior.
+  	* tests/README: Declare UTF-8 as the encoding for textual test files.
+  	* tests/channelencoding.[rvt|test]: New test to report the active Rivet
+    output-channel encoding. Verify that the response channel follows
+  	the declared UTF-8 charset.
+  	* tests/get.rvt: Convert internationalized variable names to UTF-8.
+  	* tests/headers.test: Update expected request headers for the bundled
+  	HTTP client.
+  	* tests/hello.rvt: Convert internationalized Spanish and Japanese text
+  	to UTF-8.
+  	* tests/hello.test: Convert internationalized expectations to UTF-8.
+  	* tests/include.html: Convert the Japanese include fixture to UTF-8.
+  	* tests/include.test: Update the UTF-8 include expectation and emitted
+  	whitespace.
+  	* tests/inspect.test: Make ChildInitScript inspection checks robust
+  	against additional configuration commands.
+  	* tests/parse.rvt: Parse the included template explicitly as UTF-8.
+  	* tests/parse.test: Convert parser expectations to UTF-8, normalize the
+  	trailing newline and test explicit ISO-8859-1 input decoding.
+  	* tests/parseencoding.rvt: Exercise ::rivet::parse with an explicit
+  	ISO-8859-1 encoding.
+  	* tests/parsepackage.test: Convert parser-package expectations to
+  	UTF-8.
+  	* tests/parsestring.rvt: Read the string template explicitly as UTF-8.
+  	* tests/post.rvt: Convert internationalized POST variable names to
+  	UTF-8.
+  	* tests/post.test: Convert internationalized POST requests and
+  	expectations to UTF-8.
+  	* tests/rivet.test: Enable the complete regular test list and add the
+  	response-channel encoding test.
+  	* tests/runtests.tcl: Establish UTF-8 for the test interpreter and
+  	Rivet child interpreters, replacing the obsolete UTF-8 warning.
+  	* tests/tclfile.tcl: Convert the plain Tcl internationalized fixture
+  	to UTF-8.
+  	* tests/tclfile.test: Convert the plain Tcl file expectation to UTF-8.
+  	* doc/xml/commands.xml: Document the ::rivet::parse -encoding,
+  	-virtual and -string forms.
+
 2026-04-19 Massimo Manghi <mx...@apache.org>
 	* rivet/packages/dio/dio_Tdbc.tcl: trimming sql command string before
 	testing the presence of a terminating ';'
diff --git a/doc/xml/commands.xml b/doc/xml/commands.xml
index 6c727cb..13936a9 100644
--- a/doc/xml/commands.xml
+++ b/doc/xml/commands.xml
@@ -1422,8 +1422,15 @@ bab</programlisting>
 	    <refsynopsisdiv>
 		<cmdsynopsis>
 		    <command>::rivet::parse</command>
+		    <arg><option>-encoding <replaceable>encoding</replaceable></option></arg>
+		    <arg><option>-virtual</option></arg>
 		    <arg><replaceable>filename</replaceable></arg>
 		</cmdsynopsis>
+		<cmdsynopsis>
+		    <command>::rivet::parse</command>
+		    <arg choice="plain"><option>-string</option></arg>
+		    <arg choice="plain"><replaceable>template_string</replaceable></arg>
+		</cmdsynopsis>
 	    </refsynopsisdiv>
 
 	    <refsect1>
@@ -1432,6 +1439,12 @@ bab</programlisting>
 		    Like the Tcl <command>source</command> command, but also
 		    parses for Rivet &lt;?  and ?&gt; processing tags.  Using
 		    this command, you can use one .rvt file from another.
+		    The optional <option>-encoding</option> argument selects the
+		    external character encoding used to read the file. When omitted,
+		    the Tcl system encoding is retained for compatibility. Newline
+		    translation is disabled when an explicit encoding is selected.
+		    The <option>-string</option> form accepts an existing Tcl string
+		    and therefore performs no character decoding.
 		</para>
 	    </refsect1>
 	</refentry>
diff --git a/src/mod_rivet_ng/TclWebapache.c b/src/mod_rivet_ng/TclWebapache.c
index 83ce695..5906856 100644
--- a/src/mod_rivet_ng/TclWebapache.c
+++ b/src/mod_rivet_ng/TclWebapache.c
@@ -133,12 +133,26 @@ TclWeb_InitRequest(rivet_thread_private* private, Tcl_Interp *interp)
 
         charset = (char *) strstr(r->content_type,"charset");
         if (charset != NULL) {
+            char* charset_value;
+            Tcl_Channel outchannel;
+
             charset = apr_pstrdup(r->pool,charset);
 
             /* ther's some freedom about spaces in the AddType lines: let's strip them off */
 
             apr_collapse_spaces(charset,charset);
             req->charset = charset;
+
+            /* The response charset is also the external encoding of the
+             * Tcl output channel. Configure it for every request so a prior
+             * binary response cannot leak its channel state. */
+            charset_value = strchr(charset, '=');
+            outchannel = Tcl_GetStdChannel(TCL_STDOUT);
+            if (charset_value != NULL && outchannel != NULL &&
+                Tcl_SetChannelOption(interp, outchannel, "-encoding",
+                                     charset_value + 1) != TCL_OK) {
+                return TCL_ERROR;
+            }
         }
     }
 
diff --git a/src/mod_rivet_ng/rivetCore.c b/src/mod_rivet_ng/rivetCore.c
index 22dbf3e..8a14714 100644
--- a/src/mod_rivet_ng/rivetCore.c
+++ b/src/mod_rivet_ng/rivetCore.c
@@ -209,22 +209,24 @@ TCL_CMD_HEADER(Rivet_Parse)
     rivet_thread_interp*    rivet_interp;
     Tcl_HashEntry*          entry  = NULL;
     Tcl_Obj*                script = NULL;
+    const char*             encoding = NULL;
     int                     result;
 
     THREAD_PRIVATE_DATA(private)
     CHECK_REQUEST_REC(private,"::rivet::parse")
 
-    if( objc < 2 || objc > 3 )
+    if (objc < 2 || objc > 5)
     {
-        Tcl_WrongNumArgs(interp, 1, objv, "?-virtual? filename");
+        Tcl_WrongNumArgs(interp, 1, objv,
+                         "?-encoding name? ?-virtual? filename | -string template_string");
         return TCL_ERROR;
     }
 
-    if( objc == 2 ) {
+    if (objc == 2) {
 
         filename = Tcl_GetStringFromObj(objv[1],(Tcl_Size *)NULL);
 
-    } else {
+    } else if (objc == 3) {
 
         if (STREQU(Tcl_GetStringFromObj(objv[1],(Tcl_Size *)NULL),"-virtual")) {
 
@@ -259,11 +261,41 @@ TCL_CMD_HEADER(Rivet_Parse)
 
         } else {
 
-            Tcl_WrongNumArgs(interp,1,objv,"?-virtual? filename | -string template_string");
+            Tcl_WrongNumArgs(interp,1,objv,
+                             "?-encoding name? ?-virtual? filename | -string template_string");
             return TCL_ERROR;
 
         }
 
+    } else if (objc == 4 &&
+               STREQU(Tcl_GetStringFromObj(objv[1], NULL), "-encoding")) {
+
+        encoding = Tcl_GetStringFromObj(objv[2], NULL);
+        filename = Tcl_GetStringFromObj(objv[3], NULL);
+
+    } else if (objc == 5 &&
+               STREQU(Tcl_GetStringFromObj(objv[1], NULL), "-encoding") &&
+               STREQU(Tcl_GetStringFromObj(objv[3], NULL), "-virtual")) {
+
+        encoding = Tcl_GetStringFromObj(objv[2], NULL);
+        filename = TclWeb_GetVirtualFile(private->req,
+                                         Tcl_GetStringFromObj(objv[4], NULL));
+
+    } else {
+        Tcl_WrongNumArgs(interp,1,objv,
+                         "?-encoding name? ?-virtual? filename | -string template_string");
+        return TCL_ERROR;
+    }
+
+    if (encoding != NULL) {
+        Tcl_Encoding encoding_handle = Tcl_GetEncoding(interp, encoding);
+
+        if (encoding_handle == NULL) {
+            return TCL_ERROR;
+        }
+        encoding = apr_pstrdup(private->pool,
+                               Tcl_GetEncodingName(encoding_handle));
+        Tcl_FreeEncoding(encoding_handle);
     }
 
     if (!strcmp(filename, private->r->filename))
@@ -284,7 +316,11 @@ TCL_CMD_HEADER(Rivet_Parse)
     /* */
 
     cache_key =
-        RivetCache_MakeKey( private->pool,filename,
+        RivetCache_MakeKey( private->pool,
+                            encoding == NULL
+                                ? filename
+                                : apr_psprintf(private->pool, "%s|encoding=%s",
+                                               filename, encoding),
                             finfo_b.ctime,finfo_b.mtime,
                             IS_USER_CONF(private->running_conf),0);
 
@@ -296,7 +332,7 @@ TCL_CMD_HEADER(Rivet_Parse)
         script = Tcl_NewObj();
         Tcl_IncrRefCount(script);
 
-        result = Rivet_GetRivetFile(filename,script,interp);
+        result = Rivet_GetRivetFileEncoding(filename,script,interp,encoding);
         if (result != TCL_OK)
         {
             Tcl_AddErrorInfo(interp,apr_pstrcat(private->pool,"Could not read file ",filename,NULL));
diff --git a/src/parser/rivetParser.c b/src/parser/rivetParser.c
index 12a261d..76a7ec0 100644
--- a/src/parser/rivetParser.c
+++ b/src/parser/rivetParser.c
@@ -97,6 +97,13 @@ Rivet_GetTclFile(char *filename, Tcl_Obj *outbuf, Tcl_Interp *interp)
 
 int
 Rivet_GetRivetFile(char *filename, Tcl_Obj *outbuf, Tcl_Interp *interp)
+{
+    return Rivet_GetRivetFileEncoding(filename, outbuf, interp, NULL);
+}
+
+int
+Rivet_GetRivetFileEncoding(char *filename, Tcl_Obj *outbuf,
+                           Tcl_Interp *interp, const char *encoding)
 {
     int sz = 0;
     Tcl_Obj *inbuf;
@@ -114,6 +121,17 @@ Rivet_GetRivetFile(char *filename, Tcl_Obj *outbuf, Tcl_Interp *interp)
         return TCL_ERROR;
     }
 
+    if (encoding != NULL) {
+        /* Preserve line endings while decoding the file into Tcl text. */
+        if (Tcl_SetChannelOption(interp, rivetfile,
+                                 "-translation", "binary") != TCL_OK ||
+            Tcl_SetChannelOption(interp, rivetfile,
+                                 "-encoding", encoding) != TCL_OK) {
+            Tcl_Close(interp, rivetfile);
+            return TCL_ERROR;
+        }
+    }
+
     Tcl_AppendToObj(outbuf, "puts -nonewline \"", -1);
     inbuf = Tcl_NewObj();
     Tcl_IncrRefCount(inbuf);
@@ -261,4 +279,3 @@ Rivet_Parser(Tcl_Obj *outbuf, Tcl_Obj *inbuf)
 
     return inside;
 }
-
diff --git a/src/parser/rivetParser.h b/src/parser/rivetParser.h
index 16bccf2..70522fd 100644
--- a/src/parser/rivetParser.h
+++ b/src/parser/rivetParser.h
@@ -26,6 +26,8 @@
 #endif /* BUILD_rivet */
 
 EXTERN int Rivet_GetRivetFile (char *filename, Tcl_Obj *outbuf, Tcl_Interp *interp);
+EXTERN int Rivet_GetRivetFileEncoding(char *filename, Tcl_Obj *outbuf,
+                                      Tcl_Interp *interp, const char *encoding);
 EXTERN int Rivet_GetTclFile(char *filename, Tcl_Obj *outbuf, Tcl_Interp *interp);
 EXTERN int Rivet_Parser(Tcl_Obj *outbuf, Tcl_Obj *inbuf);
 
diff --git a/tests/README b/tests/README
index 2f0e6f4..ba3a776 100644
--- a/tests/README
+++ b/tests/README
@@ -5,6 +5,13 @@ These tests are intended to automate the testing of core Rivet
 features.  They are not complete at this point, and work on them would
 be welcome.
 
+Character encoding
+------------------
+
+All textual test scripts and fixtures are encoded as UTF-8. The test
+runner configures both its Tcl interpreter and Rivet's request interpreters
+for UTF-8. Binary fixtures are exempt from this text-encoding contract.
+
 How to run the tests:
 --------------------
 
diff --git a/tests/apachetest/apachetest.tcl b/tests/apachetest/apachetest.tcl
index d84613b..145b25f 100644
--- a/tests/apachetest/apachetest.tcl
+++ b/tests/apachetest/apachetest.tcl
@@ -54,8 +54,8 @@ proc kill {signal pid} {
     }
 }
 
-package require http
-#source [file join [file dirname [info script]] http.tcl]
+#package require http
+source [file join [file dirname [info script]] http.tcl]
 
 namespace eval apachetest {
 
diff --git a/tests/bailout.test b/tests/bailout.test
index 198bac1..020f701 100644
--- a/tests/bailout.test
+++ b/tests/bailout.test
@@ -20,7 +20,7 @@
         set redirect_code [dict create {*}[read $rdfp]]
         set r1 [dict exists $redirect_code location]
         set r2 [dict exists $redirect_code error_code]
-    } 
+    }
     list $r1 $r2
 } {1 1}
 
@@ -31,11 +31,12 @@
         RivetServerConf AbortScript "set abcode \[::rivet::abort_code\]"
         RivetServerConf AbortScript "puts -nonewline \[::rivet::abort_page -exiting\]"
         RivetServerConf AbortScript "puts -nonewline \\\" \[dict get \$abcode error_code\] \[dict get \$abcode return_code\]\\\""
+        RivetServerConf AbortScript "flush stdout"
     } {
-        puts "test exit command"
         set url "${urlbase}exit.tcl"
+        #puts "test exit command (http [package require http]: $url)"
         set page [::http::geturl $url]
-        set r [::http::data $page]
+        set r    [::http::data $page]
         ::http::cleanup $page
     }
     set r
@@ -46,7 +47,7 @@
     } {
         set url "${urlbase}catch.rvt"
         set page [::http::geturl $url]
-        set r [::http::data $page]
+        set r    [::http::data $page]
         ::http::cleanup $page
     }
     set r [string trim $r]
diff --git a/tests/exit.tcl b/tests/exit.tcl
index d104ed9..e70b0d3 100644
--- a/tests/exit.tcl
+++ b/tests/exit.tcl
@@ -1,8 +1,7 @@
 # -- exit.tcl
 #
-# testing effects of calling the core exit command which
-# actually should have been trapped by ::rivet::exit
+# testing the effects of calling the core exit command which
+# actually is being shadowed by ::rivet::exit
 #
-# $Id: $
 
 ::exit 100
diff --git a/tests/get.rvt b/tests/get.rvt
index f235ad2..c351a6d 100644
--- a/tests/get.rvt
+++ b/tests/get.rvt
@@ -9,8 +9,8 @@ if { [::rivet::var number] > 0 } {
         puts "\[::rivet::var exists xst\]\[::rivet::var exists noxst\] = [::rivet::var exists xst] [::rivet::var exists noxst]\n"
         puts "\[::rivet::var_qs exists xst\]\[::rivet::var_qs exists noxst\] = [::rivet::var_qs exists xst] [::rivet::var_qs exists noxst]\n"
     }
-    if { [::rivet::var exists M�s] } {
-        puts "\[::rivet::var get M�s\] = [::rivet::var get M�s]\n"
+    if { [::rivet::var exists Más] } {
+        puts "\[::rivet::var get Más\] = [::rivet::var get Más]\n"
     }
     if { [::rivet::var exists lstvar1] } {
         puts "\[::rivet::var get lstvar1\] = [::rivet::var get lstvar1]\n"
diff --git a/tests/headers.test b/tests/headers.test
index 25ae042..0fa8b18 100644
--- a/tests/headers.test
+++ b/tests/headers.test
@@ -12,17 +12,13 @@ set httpversion [package require http]
 # shipped with rivet. We try to test more consistently the headers
 # as they are received by mod_rivet and returned in ::rivet::load_headers 
 
-
-set result "hdrs(Accept)     = */*
-hdrs(Host)       = localhost:8081
-hdrs(User-Agent) = Tcl http client package $httpversion"
-
 ::tcltest::test headers-1.1 {load_headers test} {
-    set headers_list [list Host $host User-Agent "Tcl http client package $httpversion"]
+    set headers_list [list Host $host]
     set token [::http::geturl ${urlbase}$testfilename1 -headers $headers_list]
     set nmatches 0
     set page [::http::data $token]
-    foreach {header_name header_value} [list Host $host Accept "\\*/\\*" User-Agent "Mozilla.+Tcl http client package $httpversion"] {
+
+    foreach {header_name header_value} [list Host $host Accept "\\*/\\*" User-Agent "Tcl http client package $httpversion"] {
         set re_exp [subst {^hdrs\\($header_name\\)\\s+=\\s+$header_value\$}]
         incr nmatches [regexp -all -lineanchor $re_exp $page]
     }
diff --git a/tests/hello.rvt b/tests/hello.rvt
index b160f62..520d1bc 100644
--- a/tests/hello.rvt
+++ b/tests/hello.rvt
@@ -4,7 +4,7 @@
 puts "Hello, World\n"
 
 # i18n-1.1
-puts "� � � � � � - El Burro Sabe M�s Que T�!\n"
+puts "¡ À È Ì Ò Ù - El Burro Sabe Más Que Tú!\n"
 
 ?>
-<p>���ܸ�(EUC-JP Japanese text)</p>
+<p>日本語 (UTF-8 Japanese text)</p>
diff --git a/tests/hello.test b/tests/hello.test
index 1ddfd81..c4d4420 100644
--- a/tests/hello.test
+++ b/tests/hello.test
@@ -11,8 +11,8 @@ set testfilename1 hello.rvt
 
 ::tcltest::test i18n-1.1 {I18N test} {
     set page [::http::geturl "${urlbase}$testfilename1"]
-    regexp -line {^� � � � � � - El Burro Sabe M�s Que T�!$} [::http::data $page] match
+    regexp -line {^¡ À È Ì Ò Ù - El Burro Sabe Más Que Tú!$} [::http::data $page] match
     ::http::cleanup $page
     set match
-} {� � � � � � - El Burro Sabe M�s Que T�!}
+} {¡ À È Ì Ò Ù - El Burro Sabe Más Que Tú!}
 
diff --git a/tests/include.html b/tests/include.html
index f18b8fa..30906b9 100644
--- a/tests/include.html
+++ b/tests/include.html
@@ -8,4 +8,4 @@
     </tr>
       </tbody>
     </table>
-<p>���ܸ�(EUC-JP Japanese text)</p>
\ No newline at end of file
+<p>日本語 (UTF-8 Japanese text)</p>
diff --git a/tests/include.test b/tests/include.test
index 386b29c..c3f0a65 100644
--- a/tests/include.test
+++ b/tests/include.test
@@ -21,6 +21,7 @@ set testfilename1 include.rvt
     </tr>
       </tbody>
     </table>
-<p>���ܸ�(EUC-JP Japanese text)</p>
+<p>日本語 (UTF-8 Japanese text)</p>
+
   </body>
 </html>}
diff --git a/tests/inspect.test b/tests/inspect.test
index 4268729..ed10061 100644
--- a/tests/inspect.test
+++ b/tests/inspect.test
@@ -2,26 +2,31 @@
 ::tcltest::test inspect-1.1 {basic introspection 1.1} {
     apachetest::start { 
             -c "RivetServerConf ChildInitScript \"set init 1\"" } {} {
+        set match 0
         catch {
             set inspect_page [::http::geturl "${urlbase}inspect.tcl?p=childinit"]
-            set match [string trim [::http::data $inspect_page]]
+            set response [string trim [::http::data $inspect_page]]
             ::http::cleanup $inspect_page
+
+            set match [regexp -all {set\s+init\s+1} $response]
         }
     }
     set match
-} {set init 1}
+} 1
 
 ::tcltest::test inspect-1.2 {basic introspection 1.2} {
     apachetest::start { 
             -c "RivetServerConf ChildInitScript \"set init 1\"" } {} {
+        set match 0
         catch {
             set inspect_page [::http::geturl "${urlbase}inspect.tcl"]
-            set match [string trim [::http::data $inspect_page]]
+            set response [string trim [::http::data $inspect_page]]
             ::http::cleanup $inspect_page
+            set match [regexp -all {server {ChildInitScript {.+set\s+init\s+1}}} $response]
         }
     }
     set match
-} {server {ChildInitScript {set init 1}}}
+} 1
 
 ::tcltest::test inspect-1.3 {basic introspection 1.3} {
     file copy -force inspect.tcl /tmp/
diff --git a/tests/parse.rvt b/tests/parse.rvt
index 4ce0313..4c17bc7 100644
--- a/tests/parse.rvt
+++ b/tests/parse.rvt
@@ -6,6 +6,6 @@
 
   <body>
     <h1>Parse Test</h1>
-    <? ::rivet::parse hello.rvt ?>
+    <? ::rivet::parse -encoding utf-8 hello.rvt ?>
   </body>
-</html>
\ No newline at end of file
+</html>
diff --git a/tests/parse.test b/tests/parse.test
index fb1e1f6..8c913bf 100644
--- a/tests/parse.test
+++ b/tests/parse.test
@@ -4,7 +4,7 @@ set testfilename1 parse.rvt
 
 ::tcltest::test parse-1.1 {Parse command} {
     set page [ ::http::geturl "${urlbase}$testfilename1" ]
-    ::http::data $page
+    string trimright [::http::data $page] "\n"
 } {<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
   <head>
@@ -15,10 +15,10 @@ set testfilename1 parse.rvt
     <h1>Parse Test</h1>
     Hello, World
 
-� � � � � � - El Burro Sabe M�s Que T�!
+¡ À È Ì Ò Ù - El Burro Sabe Más Que Tú!
 
 
-<p>���ܸ�(EUC-JP Japanese text)</p>
+<p>日本語 (UTF-8 Japanese text)</p>
 
   </body>
 </html>}
@@ -27,7 +27,7 @@ set testfilename2 parsestring.rvt
 
 ::tcltest::test parse-1.2 {Parse command} {
     set page [ ::http::geturl "${urlbase}$testfilename2" ]
-    ::http::data $page
+    string trimright [::http::data $page] "\n"
 } {<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
   <head>
@@ -38,10 +38,40 @@ set testfilename2 parsestring.rvt
     <h1>Parse String Test</h1>
     Hello, World
 
-� � � � � � - El Burro Sabe M�s Que T�!
+¡ À È Ì Ò Ù - El Burro Sabe Más Que Tú!
 
 
-<p>���ܸ�(EUC-JP Japanese text)</p>
+<p>日本語 (UTF-8 Japanese text)</p>
 
   </body>
 </html>}
+
+::tcltest::test parse-1.3 {Parse command with explicit legacy encoding} \
+    -setup {
+        set legacyFile parse-iso8859-1.tmp
+        set channel [open $legacyFile w]
+        fconfigure $channel -translation binary -encoding binary
+        puts -nonewline $channel [encoding convertto iso8859-1 {
+            <? puts -nonewline "Más" ?>
+        }]
+        close $channel
+        unset channel
+    } \
+    -body {
+        set page [::http::geturl "${urlbase}parseencoding.rvt"]
+        set data [::http::data $page]
+        regexp {Más} $data
+    } \
+    -cleanup {
+        if {[info exists page]} {
+            ::http::cleanup $page
+        }
+        if {[info exists channel]} {
+            close $channel
+        }
+        if {[info exists legacyFile]} {
+            file delete -force $legacyFile
+        }
+        unset -nocomplain page data channel legacyFile
+    } \
+    -result 1
diff --git a/tests/parsepackage.test b/tests/parsepackage.test
index 6e5734f..951fa72 100644
--- a/tests/parsepackage.test
+++ b/tests/parsepackage.test
@@ -17,11 +17,11 @@ load [file join [pwd] .. src .libs librivetparser[info sharedlibext]]
 puts "Hello, World\n"
 
 # i18n-1.1
-puts "� � � � � � - El Burro Sabe M�s Que T�!\n"
+puts "¡ À È Ì Ò Ù - El Burro Sabe Más Que Tú!\n"
 
 
 puts -nonewline "
-<p>���ܸ�(EUC-JP Japanese text)</p>
+<p>日本語 (UTF-8 Japanese text)</p>
 "
 }
 
@@ -35,11 +35,11 @@ puts -nonewline ""
 puts "Hello, World\n"
 
 # i18n-1.1
-puts "� � � � � � - El Burro Sabe M�s Que T�!\n"
+puts "¡ À È Ì Ò Ù - El Burro Sabe Más Que Tú!\n"
 
 
 puts -nonewline "
-<p>���ܸ�(EUC-JP Japanese text)</p>
+<p>日本語 (UTF-8 Japanese text)</p>
 "
 
 }
diff --git a/tests/parsestring.rvt b/tests/parsestring.rvt
index e25b2d5..8264059 100644
--- a/tests/parsestring.rvt
+++ b/tests/parsestring.rvt
@@ -6,6 +6,6 @@
 
   <body>
     <h1>Parse String Test</h1>
-    <? ::rivet::parse -string [::rivet::read_file hello.rvt] ?>
+    <? ::rivet::parse -string [::rivet::read_file hello.rvt -encoding utf-8] ?>
   </body>
-</html>
\ No newline at end of file
+</html>
diff --git a/tests/post.rvt b/tests/post.rvt
index a887723..91fc8ab 100644
--- a/tests/post.rvt
+++ b/tests/post.rvt
@@ -7,8 +7,8 @@ if { [ ::rivet::var number ] > 0 } {
         puts "\[::rivet::var_post get foobar\] = [::rivet::var_post get foobar]\n"
     }
     # get/post variables 1.{2,3}
-    if { [ ::rivet::var exists M�s ] } {
-        puts "\[::rivet::var get M�s\] = [::rivet::var get M�s]\n"
+    if { [ ::rivet::var exists Más ] } {
+        puts "\[::rivet::var get Más\] = [::rivet::var get Más]\n"
     }
     if { [::rivet::var exists lstvar1] } {
         puts "\[::rivet::var get lstvar1\] = [::rivet::var get lstvar1]\n"
diff --git a/tests/post.test b/tests/post.test
index bb7a737..70e331b 100644
--- a/tests/post.test
+++ b/tests/post.test
@@ -9,16 +9,16 @@ set testfilename1 post.rvt
 } {[::rivet::var get foobar] = goober}
 
 ::tcltest::test postvariables-2.1 {POST variables + I18N} {
-    set page [ ::http::geturl "${urlbase}$testfilename1" -query M�s=T� ]
-    regexp -line {^\[::rivet::var get M�s\] = T�$} [ ::http::data $page ] match
+    set page [ ::http::geturl "${urlbase}$testfilename1" -query Más=Tú ]
+    regexp -line {^\[::rivet::var get Más\] = Tú$} [ ::http::data $page ] match
     set match
-} {[::rivet::var get M�s] = T�}
+} {[::rivet::var get Más] = Tú}
 
 ::tcltest::test postvariables-2.2 {POST variables + I18N + encoding} {
-    set page [ ::http::geturl "${urlbase}$testfilename1" -query [ ::http::formatQuery M�s T� ] ]
-    regexp -line {^\[::rivet::var get M�s\] = T�$} [ ::http::data $page ] match
+    set page [ ::http::geturl "${urlbase}$testfilename1" -query [ ::http::formatQuery Más Tú ] ]
+    regexp -line {^\[::rivet::var get Más\] = Tú$} [ ::http::data $page ] match
     set match
-} {[::rivet::var get M�s] = T�}
+} {[::rivet::var get Más] = Tú}
 
 ::tcltest::test postvariables-3.1 {POST multi-value variable} {
     set page [ ::http::geturl "${urlbase}get.rvt" -query [::http::formatQuery lstvar1 a lstvar1 b lstvar1 {c d}]]
diff --git a/tests/rivet.test b/tests/rivet.test
index d6cabee..1675b0f 100755
--- a/tests/rivet.test
+++ b/tests/rivet.test
@@ -35,11 +35,10 @@ set urlbase "http://${host}:8081/"
 if {[info exists ::env(TestList)]} {
     set TestList $::env(TestList)
 } else {
-    set TestList {rivetlib.test shorthand.test headers.test cookies.test}
-    set untestList { 
-		cookies.test get.test post.test tclfile.test \
-		env.test hello.test include.test binary.test \
-		parse.test upload.test makeurl.test commands.test }
+    set TestList { rivetlib.test shorthand.test headers.test channelencoding.test cookies.test
+                   get.test post.test tclfile.test \
+                   env.test hello.test include.test binary.test \
+                   parse.test upload.test makeurl.test commands.test }
 }
 
 # Test stanzas are created by giving the test a name and a
@@ -103,4 +102,3 @@ if { $testgroup3 } {
 }
 
 ::tcltest::cleanupTests
-
diff --git a/tests/runtests.tcl b/tests/runtests.tcl
index f55c506..0ba5108 100755
--- a/tests/runtests.tcl
+++ b/tests/runtests.tcl
@@ -21,6 +21,10 @@ set default_mpm     prefork
 set httpd_args      {}
 set rivetlib_path   {}
 
+# Test scripts and textual fixtures are UTF-8 independently of the locale
+# from which the suite is started.
+encoding system utf-8
+
 proc runtests_usage {} {
     puts stderr "Usage: $::argv0 /path/to/apache/httpd ?startserver? ?-mpm <MPM module>? ?-bridge <MPM Bridge>? -rivetlib <rivetlib-root>"
     exit 1
@@ -99,15 +103,6 @@ puts stderr "Tests will be run against apache ${::httpd_version} version with th
 
 package require apachetest
 
-#if { [encoding system] eq "utf-8" } {
-#    puts stderr {
-#        System encoding is utf-8 - this is known to cause problems
-#        with the test environment!  Continuing with tests in 5 seconds
-#        using the iso8859-1 encoding.
-#    }
-#    after 5000
-#}
-
 if { [catch {
     apachetest::getbinname $httpd_bin
 } err ] } {
@@ -128,6 +123,8 @@ apachetest::need_modules [list \
 apachetest::makeconf server.conf $bridge {
     LoadModule rivet_module [file join $CWD .. src/.libs mod_rivet[info sharedlibextension]]
 
+    RivetServerConf ChildInitScript "encoding system utf-8"
+
     # User and Group directives removed to ease dependency of test 
     # suite from the output of command 'id' (from which
     # the values for these directives were inferred (Bug #53396)
diff --git a/tests/tclfile.tcl b/tests/tclfile.tcl
index d12cc84..19d0173 100644
--- a/tests/tclfile.tcl
+++ b/tests/tclfile.tcl
@@ -1,3 +1,3 @@
 # test file for plain .tcl files
 
-puts "� � � � � � - El Burro Sabe M�s Que T�!"
+puts "¡ À È Ì Ò Ù - El Burro Sabe Más Que Tú!"
diff --git a/tests/tclfile.test b/tests/tclfile.test
index f6fe12e..88c1a92 100644
--- a/tests/tclfile.test
+++ b/tests/tclfile.test
@@ -3,5 +3,5 @@
 ::tcltest::test tclfile-1.1 {Plain .tcl file} {
     set page [ ::http::geturl "${urlbase}tclfile.tcl" ]
     set pgdata [string trim [ ::http::data $page ] ]
-} "� � � � � � - El Burro Sabe M�s Que T�!"
+} "¡ À È Ì Ò Ù - El Burro Sabe Más Que Tú!"
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tcl.apache.org
For additional commands, e-mail: commits-help@tcl.apache.org