Skip to content
Tcl Source Code History Of Ticket 2da8d6fb3d
Login

History Of Ticket 2da8d6fb3d

Artifacts Associated With Ticket 2da8d6fb3d

  1. Ticket change [c8a90c49f9] (rid 167226) by andrew.brooks on 2018-11-08 18:08:26:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. comment initialized to:
      If a HTTP request made with the http package receives a reply with an explicit charset in the Content-Type header, the charset will only be respected when decoding the reply for certain Content-Types (text/* and several xml types).
      
      This behavior is at odds with RFC2068, section 3.7.1 ('HTTP/1.1 recipients MUST respect the charset label provided by the sender; and those user agents that have a provision to "guess" a charset MUST use the charset from the content-type field if they support that charset').
      
      The problem is easy to reproduce:
      
      1. Make a ::http::geturl request to a server that sends a reply with header 'Content-Type: application/json;charset=UTF-8' and a body containing a UTF-8 wide character.
      2. Check the response body (the wide character will be mis-encoded).
      
      Note that this does not happen if the Content-Type header is 'text;charset=UTF-8' or 'application/xml;charset=UTF-8'.
      
      I first noticed this behavior in 8.6.8, but I imagine that it has been around for a while.
      
      This patch (written against trunk) for the http package corrects the problem:
      
      --- tcl/library/http/http.tcl	2018-11-08 11:11:36.000000000 -0600
      +++ fixed/library/http/http.tcl	2018-11-08 11:11:31.000000000 -0600
      @@ -748,6 +748,7 @@
       	-validate	boolean
           }
           set state(charset)	$defaultCharset
      +    set state(explicit_charset) 0
           set options {
       	-binary -blocksize -channel -command -handler -headers -keepalive
       	-method -myaddr -progress -protocol -query -queryblocksize
      @@ -2710,9 +2711,11 @@
       				    {charset\s*=\s*\"((?:[^""]|\\\")*)\"} \
       				    $state(type) -> cs]} {
       				set state(charset) [string map {{\"} \"} $cs]
      +				set state(explicit_charset) 1
       			    } else {
      -				regexp -nocase {charset\s*=\s*(\S+?);?} \
      -					$state(type) -> state(charset)
      +				set state(explicit_charset) \
      +				    [regexp -nocase {charset\s*=\s*(\S+?);?} \
      +					 $state(type) -> state(charset)]
       			    }
       			}
       			content-length {
      @@ -3320,11 +3323,13 @@
       	    return
       	}
       
      -	if {!$state(binary)} {
      +	if {!$state(binary) || $state(explicit_charset)} {
       	    # If we are getting text, set the incoming channel's encoding
       	    # correctly.  iso8859-1 is the RFC default, but this could be any
      -	    # IANA charset.  However, we only know how to convert what we have
      -	    # encodings for.
      +	    # IANA charset.  If we were given an explicit charset in the
      +	    # Content-Type header, RFC2068 3.7.1 demands that we respect the
      +	    # explicit charset if possible.  However, we only know how to
      +	    # convert what we have encodings for.
       
       	    set enc [CharsetToEncoding $state(charset)]
       	    if {$enc ne "binary"} {
      
    5. foundin initialized to: "8.6.8"
    6. is_private initialized to: "0"
    7. login: "andrew.brooks"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "d2db30f3ad8e328ce0ed2fb6de7c0b52c59b2acd"
    10. resolution initialized to: "None"
    11. severity initialized to: "Minor"
    12. status initialized to: "Open"
    13. submitter initialized to: "andrew.brooks"
    14. subsystem initialized to: "29. http Package"
    15. title initialized to:
      http doesn't respect charset for some content-types
      
    16. type initialized to: "Bug"
  2. Add attachment "http.tcl.patch" [c69d46faa7] (rid 167227) by andrew.brooks on 2018-11-08 18:11:15.

  3. Ticket change [22a7f497a9] (rid 167228) by andrew.brooks on 2018-11-08 18:12:31:

    1. comment changed to:
      If a HTTP request made with the http package receives a reply with an explicit charset in the Content-Type header, the charset will only be respected when decoding the reply for certain Content-Types (text/* and several xml types).
      
      This behavior is at odds with RFC2068, section 3.7.1 ('HTTP/1.1 recipients MUST respect the charset label provided by the sender; and those user agents that have a provision to "guess" a charset MUST use the charset from the content-type field if they support that charset').
      
      The problem is easy to reproduce:
      
      1. Make a ::http::geturl request to a server that sends a reply with header 'Content-Type: application/json;charset=UTF-8' and a body containing a UTF-8 wide character.
      2. Check the response body (the wide character will be mis-encoded).
      
      Note that this does not happen if the Content-Type header is 'text;charset=UTF-8' or 'application/xml;charset=UTF-8'.
      
      I first noticed this behavior in 8.6.8, but I imagine that it has been around for a while.
      
      I have attached a patch (written against trunk) for the http package that corrects the problem.
      
    2. icomment: "moved patch to an attachment"
    3. login: "andrew.brooks"
    4. mimetype: "text/plain"
  4. Ticket change [2cc4a61371] (rid 185213) by kjnash on 2020-07-24 19:36:30:

    1. icomment:
      The similar bug [13657a2dc35] was fixed in Tcl 8.6.10, http 2.9.1 by identifying Content-Type application/json as not binary.
      
      This fixes the present bug for me.  If it fixes the problem for you I will close the ticket.
      
    2. login: "kjnash"
    3. mimetype: "text/plain"
  5. Ticket change [140d3fd0d3] (rid 190577) by kjnash on 2020-12-31 15:10:15:

    1. closedate changed to: "2459215.13211954"
    2. closer changed to: "kjnash"
    3. login: "kjnash"
    4. mimetype: "text/plain"
    5. resolution changed to: "Duplicate"
    6. status changed to: "Closed"