diff options
author | hobbs <hobbs> | 2004-05-25 22:50:46 (GMT) |
---|---|---|
committer | hobbs <hobbs> | 2004-05-25 22:50:46 (GMT) |
commit | bde979906035bbdc9ff1001cb4a4b64a5dd6b813 (patch) | |
tree | 3773b90b5f652f7c9a3ae818597690d3ad138bc2 /tests/http.test | |
parent | f54b39a2a3db59321f0fef9bed7f1606156deb1a (diff) | |
download | tcl-bde979906035bbdc9ff1001cb4a4b64a5dd6b813.zip tcl-bde979906035bbdc9ff1001cb4a4b64a5dd6b813.tar.gz tcl-bde979906035bbdc9ff1001cb4a4b64a5dd6b813.tar.bz2 |
* doc/http.n (http::config): add -urlencoding option (default utf-8)
* library/http/http.tcl: that specifies encoding conversion of
* library/http/pkgIndex.tcl: args for http::formatQuery. Previously
* tests/http.test: undefined, RFC 2718 says it should be
utf-8. 'http::config -urlencoding {}' returns previous behavior,
which will throw errors processing non-latin-1 chars.
Bumped http package to 2.5.0.
Diffstat (limited to 'tests/http.test')
-rw-r--r-- | tests/http.test | 64 |
1 files changed, 55 insertions, 9 deletions
diff --git a/tests/http.test b/tests/http.test index 1051162..942c9a5 100644 --- a/tests/http.test +++ b/tests/http.test @@ -12,7 +12,7 @@ # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # # -# RCS: @(#) $Id: http.test,v 1.33.2.1 2003/07/18 19:41:17 hobbs Exp $ +# RCS: @(#) $Id: http.test,v 1.33.2.2 2004/05/25 22:50:47 hobbs Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest 2 @@ -47,7 +47,7 @@ catch {unset data} # Ensure httpd file exists -set origFile [file join $::tcltest::testsDirectory httpd] +set origFile [file join [pwd] [file dirname [info script]] httpd] set httpdFile [file join [temporaryDirectory] httpd_[pid]] if {![file exists $httpdFile]} { makeFile "" $httpdFile @@ -85,7 +85,7 @@ if {[info commands testthread] == "testthread" && [file exists $httpdFile]} { test http-1.1 {http::config} { http::config -} [list -accept */* -proxyfilter http::ProxyRequired -proxyhost {} -proxyport {} -useragent "Tcl http client package $version"] +} [list -accept */* -proxyfilter http::ProxyRequired -proxyhost {} -proxyport {} -urlencoding utf-8 -useragent "Tcl http client package $version"] test http-1.2 {http::config} { http::config -proxyfilter @@ -97,15 +97,25 @@ test http-1.3 {http::config} { test http-1.4 {http::config} { set savedconf [http::config] - http::config -proxyhost nowhere.come -proxyport 8080 -proxyfilter myFilter -useragent "Tcl Test Suite" + http::config -proxyhost nowhere.come -proxyport 8080 \ + -proxyfilter myFilter -useragent "Tcl Test Suite" \ + -urlencoding iso8859-1 set x [http::config] eval http::config $savedconf set x -} {-accept */* -proxyfilter myFilter -proxyhost nowhere.come -proxyport 8080 -useragent {Tcl Test Suite}} +} {-accept */* -proxyfilter myFilter -proxyhost nowhere.come -proxyport 8080 -urlencoding iso8859-1 -useragent {Tcl Test Suite}} test http-1.5 {http::config} { list [catch {http::config -proxyhost {} -junk 8080} msg] $msg -} {1 {Unknown option -junk, must be: -accept, -proxyfilter, -proxyhost, -proxyport, -useragent}} +} {1 {Unknown option -junk, must be: -accept, -proxyfilter, -proxyhost, -proxyport, -urlencoding, -useragent}} + +test http-1.6 {http::config} { + set enc [list [http::config -urlencoding]] + http::config -urlencoding iso8859-1 + lappend enc [http::config -urlencoding] + http::config -urlencoding [lindex $enc 0] + set enc +} {utf-8 iso8859-1} test http-2.1 {http::reset} { @@ -465,14 +475,24 @@ test http-5.1 {http::formatQuery} { http::formatQuery name1 value1 name2 "value two" } {name1=value1&name2=value+two} -test http-5.2 {http::formatQuery} { - http::formatQuery name1 ~bwelch name2 \xa1\xa2\xa2 -} {name1=%7ebwelch&name2=%a1%a2%a2} +# test http-5.2 obsoleted by 5.4 and 5.4 with http 2.5 test http-5.3 {http::formatQuery} { http::formatQuery lines "line1\nline2\nline3" } {lines=line1%0d%0aline2%0d%0aline3} +test http-5.4 {http::formatQuery} { + http::formatQuery name1 ~bwelch name2 \xa1\xa2\xa2 +} {name1=%7ebwelch&name2=%c2%a1%c2%a2%c2%a2} + +test http-5.5 {http::formatQuery} { + set enc [http::config -urlencoding] + http::config -urlencoding iso8859-1 + set res [http::formatQuery name1 ~bwelch name2 \xa1\xa2\xa2] + http::config -urlencoding $enc + set res +} {name1=%7ebwelch&name2=%a1%a2%a2} + test http-6.1 {http::ProxyRequired} { http::config -proxyhost [info hostname] -proxyport $port set token [http::geturl $url] @@ -489,6 +509,31 @@ test http-7.1 {http::mapReply} { http::mapReply "abc\$\[\]\"\\()\}\{" } {abc%24%5b%5d%22%5c%28%29%7d%7b} +test http-7.2 {http::mapReply} { + # RFC 2718 specifies that we pass urlencoding on utf-8 chars by default, + # so make sure this gets converted to utf-8 then urlencoded. + http::mapReply "\u2208" +} {%e2%88%88} + +test http-7.3 {http::formatQuery} { + set enc [http::config -urlencoding] + # this would be reverting to http <=2.4 behavior + http::config -urlencoding "" + set res [list [catch {http::mapReply "\u2208"} msg] $msg] + http::config -urlencoding $enc + set res +} [list 1 "can't read \"formMap(\u2208)\": no such element in array"] + +test http-7.4 {http::formatQuery} { + set enc [http::config -urlencoding] + # this would be reverting to http <=2.4 behavior w/o errors + # (unknown chars become '?') + http::config -urlencoding "iso8859-1" + set res [http::mapReply "\u2208"] + http::config -urlencoding $enc + set res +} {%3f} + # cleanup catch {unset url} catch {unset badurl} @@ -506,4 +551,5 @@ if {[info exists removeHttpd]} { removeFile $httpdFile } +rename bgerror {} ::tcltest::cleanupTests |