[Zope] url_quote and "javascript quote"

Smith, Neil Neil.Smith@npower.com
Tue, 2 Apr 2002 09:51:12 +0100


iap@y2fun.com writes:
 > ...
 > The problem is that I can't pass binary string from server by "url_quote"
 > and decode it in the broswer by "unescape".
 > 
 > My questions:
 > 1) Is there any zope object can  be used to encode string in "javascript"
 > way in the server side?

I had a similar problem that I needed to deal with quote characters in some
form data that was being handled in javascript.  I added a new quoting
format to dtml-var.  I changed DT_Var.py in Lib\Python\DocumentTemplate to
add the following function:

def jscript_quote(v, name='(Unknown name)', md={}):
    v=str(v)
    if find(v,"\\") >= 0: v=join(split(v,"\\"),"\\\\")
    if find(v,"'") >= 0: v=join(split(v,"'"),"\\'")
    if find(v,'"') >= 0: v=join(split(v,'"'),'\\"')
    if find(v,"\t") >= 0: v=join(split(v,"\t"),"\\t")
    if find(v,"\n") >= 0: v=join(split(v,"\n"),"\\n")
    if find(v,"\r") >= 0: v=join(split(v,"\r"),"\\r")
    return v

Probably not the most efficient way to do it, but it works.  You also need
to add a reference to it in the "args=parse_params.." line, and to
"modifiers".

You could always just extend this to do the encoding of non-displayable
characters as well.  Look at the code for url_encode.

It would be nice if there was a product for this, but that's a bit beyond my
experience at present.

--
Neil Smith
Sorry about the following stuff, it's added by my company's mail server, not
by me.
**********************************************************************
 
The information contained in this e-mail is confidential and intended only for the use of the addressee. If the reader of this message is not the addressee, you are hereby notified that you have received this e-mail in error and you must not copy, disseminate, distribute, use or take any action as a result of the information contained in it.
    
If you have received this e-mail in error, please notify postmaster@npower.com (UK 01384 275454) and delete it immediately from your system.
    
Neither Npower nor any of the other companies in the Innogy group from whom this e-mail originates accept any responsibility for losses or damage as a result of any viruses and it is your responsibility to check attachments (if any) for viruses.

Npower Limited
Registered office: Windmill Hill Business Park, Whitehill Way, Swindon SN5 6PB. Registered in England and Wales: number 3653277

This e-mail may be sent on behalf of a member of the Innogy plc group of companies.

**********************************************************************