From 0a5154ce87f664c62309803df4d7b8ab14b4721d Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 10 May 2022 16:38:22 +0000 Subject: Now we're on it, keep better track with state(host) and state(path). Backported from http 2.10 --- library/http/http.tcl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/library/http/http.tcl b/library/http/http.tcl index 92d3a5a..e754264 100644 --- a/library/http/http.tcl +++ b/library/http/http.tcl @@ -931,8 +931,12 @@ proc http::geturl {url args} { } return -code error "Illegal characters in URL path" } + if {![regexp {^[^?#]+} $srvurl state(path)]} { + set state(path) / + } } else { set srvurl / + set state(path) / } if {$proto eq ""} { set proto http @@ -1409,12 +1413,16 @@ proc http::Connected {token proto phost srvurl} { puts $sock "$how $srvurl HTTP/$state(-protocol)" if {[dict exists $state(-headers) Host]} { # Allow Host spoofing. [Bug 928154] - puts $sock "Host: [dict get $state(-headers) Host]" + set hostHdr [dict get $state(-headers) Host] + regexp {^[^:]+} $hostHdr state(host) + puts $sock "Host: $hostHdr" } elseif {$port == $defport} { # Don't add port in this case, to handle broken servers. [Bug # #504508] + set state(host) $host puts $sock "Host: $host" } else { + set state(host) $host puts $sock "Host: $host:$port" } puts $sock "User-Agent: $http(-useragent)" @@ -3175,7 +3183,7 @@ proc http::BlockingGets {sock} { while 1 { set count [gets $sock line] set eof [eof $sock] - if {$count > -1 || $eof} { + if {$count >= 0 || $eof} { return $line } else { yield -- cgit v0.12 From 6d44e5c0f77c03a6daaf47db88c752018d980055 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Wed, 11 May 2022 19:06:56 +0000 Subject: Fix [6898f9cb71]: shiftjis is presumably misspelled in http 2.7.7. Also add more testcases for http::CharsetToEncoding, revealing one more bug --- library/http/http.tcl | 5 ++++- tests/http.test | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/library/http/http.tcl b/library/http/http.tcl index e754264..ae0a538 100644 --- a/library/http/http.tcl +++ b/library/http/http.tcl @@ -3479,7 +3479,7 @@ proc http::CharsetToEncoding {charset} { set encoding "iso8859-$num" } elseif {[regexp {iso-?2022-(jp|kr)} $charset -> ext]} { set encoding "iso2022-$ext" - } elseif {[regexp {shift[-_]?js} $charset]} { + } elseif {[regexp {shift[-_]?jis} $charset]} { set encoding "shiftjis" } elseif {[regexp {(?:windows|cp)-?([0-9]+)} $charset -> num]} { set encoding "cp$num" @@ -3491,6 +3491,9 @@ proc http::CharsetToEncoding {charset} { 1 - 2 - 3 { set encoding "iso8859-$num" } + default { + set encoding "binary" + } } } else { # other charset, like euc-xx, utf-8,... may directly map to encoding diff --git a/tests/http.test b/tests/http.test index c45a45a..40113dc 100644 --- a/tests/http.test +++ b/tests/http.test @@ -119,6 +119,27 @@ test http-1.6 {http::config} -setup { test http-2.1 {http::reset} { catch {http::reset http#1} } 0 +test http-2.2 {http::CharsetToEncoding} { + http::CharsetToEncoding iso-8859-11 +} iso8859-11 +test http-2.3 {http::CharsetToEncoding} { + http::CharsetToEncoding iso-2022-kr +} iso2022-kr +test http-2.4 {http::CharsetToEncoding} { + http::CharsetToEncoding shift-jis +} shiftjis +test http-2.5 {http::CharsetToEncoding} { + http::CharsetToEncoding windows-437 +} cp437 +test http-2.6 {http::CharsetToEncoding} { + http::CharsetToEncoding latin5 +} iso8859-9 +test http-2.7 {http::CharsetToEncoding} { + http::CharsetToEncoding latin1 +} iso8859-1 +test http-2.8 {http::CharsetToEncoding} { + http::CharsetToEncoding latin4 +} binary test http-3.1 {http::geturl} -returnCodes error -body { http::geturl -bogus flag -- cgit v0.12