On Mon, Nov 01, 2010 at 12:53:50PM -0700, [email protected] wrote:
> Use json.dumps instead of qjs and you have a beautiful solution there,
> and not just for strings.

IIRC I tried that and rejected it for some reason I neglected to write
down.  *sigh*


Let's experiment:

    <!% import json %>
    <% s = "it's alive!" %>
    <a href="#" onclick="alert(${s|json.dumps})">EXPERIMENT</a>

ends up as

    <a href="#" onclick="alert("it&#39;s alive!")">EXPERIMENT</a> 

and fails to work.


Try #2:

    <a href="#" onclick="alert(${s_w_a|json.dumps, escape})">EXPERIMENT</a>

ends up as

    <a href="#" onclick="alert(&#34;it&amp;#39;s alive!&#34;)">EXPERIMENT</a> 

and, when clicked, opens an alert with the text

    it&#39;s alive!

Again, failure.


Meanwhile

    <a href="#" onclick="alert(${s_w_a|qjs})">EXPERIMENT</a>

ends up as

    <a href="#" onclick="alert('it\x27s alive!')">EXPERIMENT</a> 

and, when clicked, says

    it's alive!

which is what I want.


Incidentally, that strange &#39;s quoting could be a bug -- I'm surprised
to see ' quoted while " isn't.

Marius Gedminas
-- 
The best developers are also the ones sick enough to enjoy it.
        -- moffdub on stackoverflow.com

Attachment: signature.asc
Description: Digital signature

Reply via email to