How to escape single quotes in generated JSON?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to escape single quotes in generated JSON?

Mariano Martinez Peck
Hi guys, 

I am trying to serialize a dictionary form Smalltalk with either NeoJSON or with Seaside's #asJson. Imagine something like this:

| infoDict stream | 
stream := String new writeStream.
  infoDict := Dictionary new.
  infoDict at: 'exception' put: 'a  ''escape this'' aa'.

Note that the string of 'exception' may contain single quotes inside. 

Then, at some point I do:

self requestContext responseGenerator response nextPutAll: (infoDict asJson).


Problem is the string arrives without any escaping so....when I try to do this at client side from that string:

jQuery.parseJSON(variableContainingThatString);

I get an error as single quotes inside the double quotes do not seem allowed. 
I tried a lot of combinations of "JSON.stringify" or things like:

variableContainingThatString.replace(/[\\"'']/g, ''\\$&'').replace(/\u0000/g, ''\\0''); 

but none work...

So..I wonder...can I simply escape this from server side at the time I serialize to JSON? Any special way of doing this or I hack on the resulting string? 

Thanks in advance, 


--

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: How to escape single quotes in generated JSON?

Sven Van Caekenberghe-2
Hi Mariano,

I am not sure what your specific problem is, but strings in JSON are delimited with double quotes and only double quotes should be escaped, not single quotes.

https://tools.ietf.org/html/rfc7158#page-8

NeoJSONWriter toString: { 'exception' -> 'a  ''escape this'' aa' } asDictionary.

 "'{""exception"":""a  ''escape this'' aa""}'"

STON uses single quoted strings (like Smalltalk), hence escapes them.

STON toString: { 'exception' -> 'a  ''escape this'' aa' } asDictionary.
 
 "'{''exception'':''a  \''escape this\'' aa''}'"

Note the confusing escaping done by Smalltalk, better inspect the results !!

This won't solve your problem though, I know.

Sven

> On 23 Feb 2016, at 17:37, Mariano Martinez Peck <[hidden email]> wrote:
>
> Hi guys,
>
> I am trying to serialize a dictionary form Smalltalk with either NeoJSON or with Seaside's #asJson. Imagine something like this:
>
> | infoDict stream |
> stream := String new writeStream.
>   infoDict := Dictionary new.
>   infoDict at: 'exception' put: 'a  ''escape this'' aa'.
>
> Note that the string of 'exception' may contain single quotes inside.
>
> Then, at some point I do:
>
> self requestContext responseGenerator response nextPutAll: (infoDict asJson).
>
>
> Problem is the string arrives without any escaping so....when I try to do this at client side from that string:
>
> jQuery.parseJSON(variableContainingThatString);
>
> I get an error as single quotes inside the double quotes do not seem allowed.
> I tried a lot of combinations of "JSON.stringify" or things like:
>
> variableContainingThatString.replace(/[\\"'']/g, ''\\$&'').replace(/\u0000/g, ''\\0'');
>
> but none work...
>
> So..I wonder...can I simply escape this from server side at the time I serialize to JSON? Any special way of doing this or I hack on the resulting string?
>
> Thanks in advance,
>
>
> --
> Mariano
> http://marianopeck.wordpress.com
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

form action change to external link?

kuszi


Hello Everyone!

I'm still working on my large file upload project on a windows server (so ngix won't play :( ).
I have a good uploader and also technique to solve upload outside Seaside (or VA WebCOnnection as I did before) and then come back into the session afterwards.

But to make it I need to hack the seaside form to put my own link into the ACTION=".....".

Here is what I did, but it seems that action is overwritten by Seaside to its usual internal form action (understandably)


f := html form.

f with:[

   .... form creaton code here.... works well, no problem.......
And when looking at generated page source:

<form accept-charset="utf-8" method="post" action="/uploader?_s=jdXt_Vzp8dKoK3M9&amp;_k=C197PyH7ka66mXVd">


So, how to hack my own action into the form?


thanks
Robert







_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: form action change to external link?

Alejandro Infante
Hi!
The WABrush>>with: call must be the last call to a brush. So instead of:

html form
with: [ stuff… ];

Try:

html form
with: [ stuff… ]

I have tried and it works :)

Cheers!
Alejandro

On Mar 1, 2016, at 11:30 AM, Robert Kuszinger <[hidden email]> wrote:



Hello Everyone!

I'm still working on my large file upload project on a windows server (so ngix won't play :( ).
I have a good uploader and also technique to solve upload outside Seaside (or VA WebCOnnection as I did before) and then come back into the session afterwards.

But to make it I need to hack the seaside form to put my own link into the ACTION=".....".

Here is what I did, but it seems that action is overwritten by Seaside to its usual internal form action (understandably)


f := html form.

f with:[

   .... form creaton code here.... works well, no problem.......
And when looking at generated page source:

<form accept-charset="utf-8" method="post" action="/uploader?_s=jdXt_Vzp8dKoK3M9&amp;_k=C197PyH7ka66mXVd">


So, how to hack my own action into the form?


thanks
Robert






_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: form action change to external link?

kuszi
Thanks!

I'll go like this.

R


Alejandro Infante <[hidden email]> ezt írta (időpont: 2016. márc. 1., K, 17:22):
Hi!
The WABrush>>with: call must be the last call to a brush. So instead of:

html form
with: [ stuff… ];

Try:

html form
with: [ stuff… ]

I have tried and it works :)

Cheers!
Alejandro

On Mar 1, 2016, at 11:30 AM, Robert Kuszinger <[hidden email]> wrote:



Hello Everyone!

I'm still working on my large file upload project on a windows server (so ngix won't play :( ).
I have a good uploader and also technique to solve upload outside Seaside (or VA WebCOnnection as I did before) and then come back into the session afterwards.

But to make it I need to hack the seaside form to put my own link into the ACTION=".....".

Here is what I did, but it seems that action is overwritten by Seaside to its usual internal form action (understandably)


f := html form.

f with:[

   .... form creaton code here.... works well, no problem.......
And when looking at generated page source:

<form accept-charset="utf-8" method="post" action="/uploader?_s=jdXt_Vzp8dKoK3M9&amp;_k=C197PyH7ka66mXVd">


So, how to hack my own action into the form?


thanks
Robert






_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside