url escape problem in some encoding - CheckUrl
Sun Yi-Ming <[email protected]> Wed, 4 Jan 2006 15:15:28 +0800
| Newsgroups | gmane.comp.web.html-tidy.devel |
|---|---|
| Message-ID | <[email protected]> |
hi,
when parse file encoded in double bytes format like BIG5(really
variable bytes encoding, that code in ASSCII region always use 1
byte), if that file have a bad written url format with raw chinese
word in, the problem happened.
when tidy AddCharToLexer, it will re-encode the BIG5 char into a UTF-8
format(though it's input is not unicode), latter when output, if asked,
PPrintText will transfer the code from UTF-8 to it's original
format(that is,BIG5), this routine is ok.
event comes to url, the CheckUrl will escape it's element, but the
element is UTF-8 code, the url escape element should be in the original
source encoding format, yes? or who tell me i am wrong. so i think the
CheckUrl should transfer the UTF-8 code back to it's original encoding
before escape it.
i have many pages who have no escaped url with GB2312(like BIG5), the
tidy get all the url escaped in a bad format(cannot accessed), so i
give CheckUrl a dirty hack to transfer UTF-8 code to original code
before escape it, then get urls could be reached. so who will tell me a
elegant way or solution to handle this.
my code is like this
/* if in BIG5(GB2312) encoding */
<< pos += sprintf( dest + pos, "%%%02X", (byte)c );
--
>> uint c1;
>> int forward;
>> int de = DecodeUTF8BytesToChar(&c1, c, &p[i+1], NULL, &forward);
>> if ((de == -1) || (forward==0))
>> {
>> pos += sprintf( dest + pos, "%%%02X", (byte)c );
>> }
>> else
>> {
>> pos += sprintf( dest + pos, "%%%02X%%%02X",
>> (byte) ((c1 >> 8) & 0xff),
>> (byte) (c1 & 0xff) );
>> i += forward - 1;
>> }
Thank you all.
--
simon
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click