From a7d78a8fb4183478700856b8ba6471d5157e8a5a Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 13 May 2022 10:11:39 +0000 Subject: Remove [https://core.tcl-lang.org/tcl/info/1fe8ca8d3eb87b65|Horrible Hack] to keep the old error message. Instead depend on [https://core.tcl-lang.org/tips/doc/trunk/tip/601.md|TIP #601] to let "encoding convertto" generate an exception. --- doc/http.n | 7 +------ library/http/http.tcl | 14 ++------------ tests/http.test | 7 ++++--- 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/doc/http.n b/doc/http.n index 2b2d09d..84c75b0 100644 --- a/doc/http.n +++ b/doc/http.n @@ -161,12 +161,7 @@ default is 0. . The \fIencoding\fR used for creating the x-url-encoded URLs with \fB::http::formatQuery\fR and \fB::http::quoteString\fR. -The default is \fButf-8\fR, as specified by RFC -2718. Prior to http 2.5 this was unspecified, and that behavior can be -returned by specifying the empty string (\fB{}\fR), although -\fIiso8859-1\fR is recommended to restore similar behavior but without the -\fB::http::formatQuery\fR or \fB::http::quoteString\fR -throwing an error processing non-latin-1 characters. +The default is \fButf-8\fR, as specified by RFC 2718. .TP \fB\-useragent\fR \fIstring\fR . diff --git a/library/http/http.tcl b/library/http/http.tcl index 187d203..87003e4 100644 --- a/library/http/http.tcl +++ b/library/http/http.tcl @@ -3539,18 +3539,8 @@ proc http::mapReply {string} { # a pre-computed map and [string map] to do the conversion (much faster # than [regsub]/[subst]). [Bug 1020491] - if {$http(-urlencoding) ne ""} { - set string [encoding convertto $http(-urlencoding) $string] - return [string map $formMap $string] - } - set converted [string map $formMap $string] - if {[string match "*\[\u0100-\uffff\]*" $converted]} { - regexp "\[\u0100-\uffff\]" $converted badChar - # Return this error message for maximum compatibility... :^/ - return -code error \ - "can't read \"formMap($badChar)\": no such element in array" - } - return $converted + set string [encoding convertto $http(-urlencoding) $string] + return [string map $formMap $string] } interp alias {} http::quoteString {} http::mapReply diff --git a/tests/http.test b/tests/http.test index d59d588..e3baf58 100644 --- a/tests/http.test +++ b/tests/http.test @@ -677,17 +677,18 @@ test http-7.2 {http::mapReply} { test http-7.3 {http::formatQuery} -setup { set enc [http::config -urlencoding] } -returnCodes error -body { - # this would be reverting to http <=2.4 behavior + # -urlencoding "" no longer supported. Use "iso8859-1". http::config -urlencoding "" http::mapReply "∈" } -cleanup { http::config -urlencoding $enc -} -result "can't read \"formMap(∈)\": no such element in array" +} -result {unknown encoding ""} test http-7.4 {http::formatQuery} -constraints deprecated -setup { set enc [http::config -urlencoding] } -body { # this would be reverting to http <=2.4 behavior w/o errors - # (unknown chars become '?') + # with Tcl 8.x (unknown chars become '?'), generating a + # proper exception with Tcl 9.0 http::config -urlencoding "iso8859-1" http::mapReply "∈" } -cleanup { -- cgit v0.12