[Seaside] Zinc-Seaside: Problem with POSTing UTF-8 JSON

Tomas Kukol tomas.kukol at gmail.com
Tue Jun 25 21:24:46 UTC 2013


Hi Sven.

I've had a problem when POSTing non-ascii UTF-8 characters in JSON to
Seaside REST service. I've located the problem in the method
ZnZincServerAdaptor>>requestBodyFor: where the body of ZnRequest is
translated to body of WARequest. I use Pharo 1.4 with Seaside 3.0.8
and Zinc-Seaside-SvenVanCaekenberghe.40.

When the POSTed JSON contains non-ascii UTF-8 characters (Czech
characters), they are corrupted. The problem is on the "MARKED" line, where
the array of bytes changed to string by asString.

"Problematic" code:

ZnZincServerAdaptor>>requestBodyFor: aZincRequest
 ^ (aZincRequest method ~= #TRACE
and: [ aZincRequest hasEntity
 and: [ aZincRequest entity isEmpty not
 and: [ (aZincRequest entity contentType matches: ZnMimeType
applicationFormUrlEncoded) not
and: [ (aZincRequest entity contentType matches: ZnMimeType
multiPartFormData) not ] ] ] ])
 ifTrue: [
"Seaside wants to do its own text conversions"
 aZincRequest entity bytes asString "MARKED" ]
 ifFalse: [
String new ]

I did a quick correction, which is not nice, but works for me:

ZnZincServerAdaptor>>requestBodyFor: aZincRequest
^ (aZincRequest method ~= #TRACE
 and: [ aZincRequest hasEntity
and: [ aZincRequest entity isEmpty not
and: [ (aZincRequest entity contentType matches: ZnMimeType
applicationFormUrlEncoded) not
 and: [ (aZincRequest entity contentType matches: ZnMimeType
multiPartFormData) not ] ] ] ])
ifTrue: [
"Seaside wants to do its own text conversions"
 ZnUTF8Encoder new decodeBytes: aZincRequest entity bytes "CORRECTED" ]
ifFalse: [
String new ]

My correction tries to decode byte array with ZnUTF8Encoder and the result
is OK.

Maybe I would recommend to use GRPharoUtf8Codec (although I like
ZnUTF8Encoder more) or even better self codec (self = ZnZincServerAdaptor)
to try to decode the bytes.

Regards,
Tomas Kukol
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/seaside/attachments/20130625/7ebd01bb/attachment.htm


More information about the seaside mailing list