Bug: form parameters encoding (UTF-8 vs ISO-8859-1)
andresgr <[email protected]>
| Newsgroups | gmane.comp.web.httpunit.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi.
Using httpunit 1.6.2 on Ubuntu. I have one form with method=post that returns:
System.out.println("form charset: "+ formActiv.getCharacterSet());
>>>>>>form charset: iso-8859-1
In that form i do:
formActiv.setParameter("txt1", "Clínicas");
Capturing with ethereal i get:
POST /xxxx.asp HTTP/1.1
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12)
Gecko/20051010 Firefox/1.0.7 (Ubuntu package 1.0.7)
Referer: http://xxxxx.asp?que=&donde=
Content-Type: application/x-www-form-urlencoded
Cache-Control: no-cache
Pragma: no-cache
Host: xxxx.com
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Content-Length: 190
txtAtividade=Cl%C3%ADnicas....
I.e., the parameter is encoded with UTF-8 and it should be encoded
using ISO-8859-1...
Looking at the source code i find that the method used to encode de
parameters is:
WebRequest.URLEncodedString.encode:
private String encode( String source, String characterSet ) {
if (characterSet.equalsIgnoreCase(
HttpUnitUtils.DEFAULT_CHARACTER_SET )) {
return URLEncoder.encode( source );
} else {
try {
byte[] rawBytes = source.getBytes( characterSet );
etc.
HttpUnitUtils.DEFAULT_CHARACTER_SET is 8859-1
*BUT*
URLEncode.encode(source) encodes the string using "platform's default
encoding". I'm on Ubuntu, so, default encoding = UTF-8, so, although
"form charset" = "httpunit default charset" the parameter is encoded
using UTF-8, wich is incorrect.
Si i guess the line
if (characterSet.equalsIgnoreCase(
HttpUnitUtils.DEFAULT_CHARACTER_SET ))
should be changed to
if (characterSet.equalsIgnoreCase( *PLATFROM_DEFAULT_CHARACTER_SET* ))
Unfortunately, there is no easy (portable, backwards compatible) way
in java to get that charset. See
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4772857
Another way: allways encode using given charset.
Regards.
--
-=-=-=-=-=-=-=-=-=-=-=-=-
Andrés González.
http://coyotevil.blogspot.com
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV