[Newbies] HTTP encoding into UTF8
Bert Freudenberg
bert at freudenbergs.de
Tue Nov 17 11:32:35 UTC 2009
On 16.11.2009, at 23:17, Bert Freudenberg wrote:
>
> On 16.11.2009, at 23:04, Stephane Schitter wrote:
>
>> hello,
>>
>> I am playing around with squeak to connect to webservices and I run into issues very early in the process.
>> Something to do with url encoding. Is there any reason the following code:
>>
>> 'aa aa éé aa aa' encodeForHTTP
>>
>> would generate this:
>>
>> 'aa%20aa%20%C3%A9%C3%A9%20%A9aa%20%A9aa'
>>
>> where "space" is correctly set to %20 before the 'é' gets converted, but then becomes %20%A9 afterwards. As if the %A9 of my 'é' stays in the buffer and breaks my encoding of space character.
>
> Seems you have uncovered a bug. Would be great if you could report it at
>
> http://bugs.squeak.org/
>
> Here is a workaround:
>
> 'aa aa éé aa aa' squeakToUtf8 encodeForHTTPWithTextEncoding: 'latin1'
>
> - Bert -
And in the meantime, the bug has been fixed. See below.
- Bert -
Begin forwarded message:
> From: commits at source.squeak.org
> Date: 17. November 2009 11:15:06 MEZ
> To: squeak-dev at lists.squeakfoundation.org, packages at lists.squeakfoundation.org
> Subject: [squeak-dev] The Trunk: Collections-nice.196.mcz
> Reply-To: squeak-dev at lists.squeakfoundation.org
>
> Nicolas Cellier uploaded a new version of Collections to project The Trunk:
> http://source.squeak.org/trunk/Collections-nice.196.mcz
>
> ==================== Summary ====================
>
> Name: Collections-nice.196
> Author: nice
> Time: 17 November 2009, 11:14:59 am
> UUID: 24d4a90b-3d42-0945-8f92-b25c7b464ff8
> Ancestors: Collections-nice.195
>
> Correct bug reported on beginners list
> 'aa aa éé aa aa' encodeForHTTP
>
> =============== Diff against Collections-nice.195 ===============
>
> Item was changed:
> ----- Method: String>>encodeForHTTPWithTextEncoding:conditionBlock: (in category 'converting') -----
> encodeForHTTPWithTextEncoding: encodingName conditionBlock: conditionBlock
> "change dangerous characters to their %XX form, for use in HTTP transactions"
>
> | httpSafeStream encodedStream cont |
> httpSafeStream := WriteStream on: (String new).
> encodedStream := MultiByteBinaryOrTextStream on: (String new: 6).
> encodedStream converter: (TextConverter newForEncoding: encodingName).
> self do: [:c |
> (conditionBlock value: c)
> ifTrue: [httpSafeStream nextPut: (Character value: c charCode)]
> ifFalse: [
> + encodedStream text; resetToStart.
> - encodedStream text; reset.
> encodedStream nextPut: c.
> encodedStream position: 0.
> encodedStream binary.
> cont := encodedStream contents.
> cont do: [:byte |
> httpSafeStream nextPut: $%.
> httpSafeStream nextPut: (byte // 16) asHexDigit.
> httpSafeStream nextPut: (byte \\ 16) asHexDigit.
> ].
> ].
> ].
> ^ httpSafeStream contents.
> !
>
>
More information about the Beginners
mailing list