.
D 2018-11-08T18:08:26.204
J assignee nobody
J closer nobody
J cmimetype text/plain
J comment If\sa\sHTTP\srequest\smade\swith\sthe\shttp\spackage\sreceives\sa\sreply\swith\san\sexplicit\scharset\sin\sthe\sContent-Type\sheader,\sthe\scharset\swill\sonly\sbe\srespected\swhen\sdecoding\sthe\sreply\sfor\scertain\sContent-Types\s(text/*\sand\sseveral\sxml\stypes).\r\n\r\nThis\sbehavior\sis\sat\sodds\swith\sRFC2068,\ssection\s3.7.1\s('HTTP/1.1\srecipients\sMUST\srespect\sthe\scharset\slabel\sprovided\sby\sthe\ssender;\sand\sthose\suser\sagents\sthat\shave\sa\sprovision\sto\s"guess"\sa\scharset\sMUST\suse\sthe\scharset\sfrom\sthe\scontent-type\sfield\sif\sthey\ssupport\sthat\scharset').\r\n\r\nThe\sproblem\sis\seasy\sto\sreproduce:\r\n\r\n1.\sMake\sa\s::http::geturl\srequest\sto\sa\sserver\sthat\ssends\sa\sreply\swith\sheader\s'Content-Type:\sapplication/json;charset=UTF-8'\sand\sa\sbody\scontaining\sa\sUTF-8\swide\scharacter.\r\n2.\sCheck\sthe\sresponse\sbody\s(the\swide\scharacter\swill\sbe\smis-encoded).\r\n\r\nNote\sthat\sthis\sdoes\snot\shappen\sif\sthe\sContent-Type\sheader\sis\s'text;charset=UTF-8'\sor\s'application/xml;charset=UTF-8'.\r\n\r\nI\sfirst\snoticed\sthis\sbehavior\sin\s8.6.8,\sbut\sI\simagine\sthat\sit\shas\sbeen\saround\sfor\sa\swhile.\r\n\r\nThis\spatch\s(written\sagainst\strunk)\sfor\sthe\shttp\spackage\scorrects\sthe\sproblem:\r\n\r\n---\stcl/library/http/http.tcl\t2018-11-08\s11:11:36.000000000\s-0600\r\n+++\sfixed/library/http/http.tcl\t2018-11-08\s11:11:31.000000000\s-0600\r\n@@\s-748,6\s+748,7\s@@\r\n\s\t-validate\tboolean\r\n\s\s\s\s\s}\r\n\s\s\s\s\sset\sstate(charset)\t$defaultCharset\r\n+\s\s\s\sset\sstate(explicit_charset)\s0\r\n\s\s\s\s\sset\soptions\s{\r\n\s\t-binary\s-blocksize\s-channel\s-command\s-handler\s-headers\s-keepalive\r\n\s\t-method\s-myaddr\s-progress\s-protocol\s-query\s-queryblocksize\r\n@@\s-2710,9\s+2711,11\s@@\r\n\s\t\t\t\t\s\s\s\s{charset\\s*=\\s*\\"((?:[^""]|\\\\\\")*)\\"}\s\\\r\n\s\t\t\t\t\s\s\s\s$state(type)\s->\scs]}\s{\r\n\s\t\t\t\tset\sstate(charset)\s[string\smap\s{{\\"}\s\\"}\s$cs]\r\n+\t\t\t\tset\sstate(explicit_charset)\s1\r\n\s\t\t\t\s\s\s\s}\selse\s{\r\n-\t\t\t\tregexp\s-nocase\s{charset\\s*=\\s*(\\S+?);?}\s\\\r\n-\t\t\t\t\t$state(type)\s->\sstate(charset)\r\n+\t\t\t\tset\sstate(explicit_charset)\s\\\r\n+\t\t\t\t\s\s\s\s[regexp\s-nocase\s{charset\\s*=\\s*(\\S+?);?}\s\\\r\n+\t\t\t\t\t\s$state(type)\s->\sstate(charset)]\r\n\s\t\t\t\s\s\s\s}\r\n\s\t\t\t}\r\n\s\t\t\tcontent-length\s{\r\n@@\s-3320,11\s+3323,13\s@@\r\n\s\t\s\s\s\sreturn\r\n\s\t}\r\n\s\r\n-\tif\s{!$state(binary)}\s{\r\n+\tif\s{!$state(binary)\s||\s$state(explicit_charset)}\s{\r\n\s\t\s\s\s\s#\sIf\swe\sare\sgetting\stext,\sset\sthe\sincoming\schannel's\sencoding\r\n\s\t\s\s\s\s#\scorrectly.\s\siso8859-1\sis\sthe\sRFC\sdefault,\sbut\sthis\scould\sbe\sany\r\n-\t\s\s\s\s#\sIANA\scharset.\s\sHowever,\swe\sonly\sknow\show\sto\sconvert\swhat\swe\shave\r\n-\t\s\s\s\s#\sencodings\sfor.\r\n+\t\s\s\s\s#\sIANA\scharset.\s\sIf\swe\swere\sgiven\san\sexplicit\scharset\sin\sthe\r\n+\t\s\s\s\s#\sContent-Type\sheader,\sRFC2068\s3.7.1\sdemands\sthat\swe\srespect\sthe\r\n+\t\s\s\s\s#\sexplicit\scharset\sif\spossible.\s\sHowever,\swe\sonly\sknow\show\sto\r\n+\t\s\s\s\s#\sconvert\swhat\swe\shave\sencodings\sfor.\r\n\s\r\n\s\t\s\s\s\sset\senc\s[CharsetToEncoding\s$state(charset)]\r\n\s\t\s\s\s\sif\s{$enc\sne\s"binary"}\s{
J foundin 8.6.8
J is_private 0
J login andrew.brooks
J priority 5\sMedium
J private_contact d2db30f3ad8e328ce0ed2fb6de7c0b52c59b2acd
J resolution None
J severity Minor
J status Open
J submitter andrew.brooks
J subsystem 29.\shttp\sPackage
J title http\sdoesn't\srespect\scharset\sfor\ssome\scontent-types
J type Bug
K 2da8d6fb3d26031a8327b6bcda91f4fd158b71a8
U andrew.brooks
Z 0e7288e6ae814b7d36be8fa1babf653d