Re: [Web-SIG] JavaScript escape function

2005-04-26 Thread Paul Moore
On 4/26/05, Donovan Preston <[EMAIL PROTECTED]> wrote: > I'm trying to show my wife how to get some simple things done with > PHP, mostly because there are huge reference books she can read and > follow. (It's unfortunate that there are no nice Python solutions I > can teach her, including my own,

Re: [Web-SIG] JavaScript escape function

2005-04-25 Thread Shannon -jj Behrens
> Quoting is so difficult to get right that if many people reimplement > quoting, some of the implementations are sure to be wrong simply because > there are so many corner cases. It seems like this might be one area where > it would be both beneficial and possible to share code between Python web

Re: [Web-SIG] JavaScript escape function

2005-04-25 Thread Shannon -jj Behrens
> I'm trying to show my wife how to get some simple things done with > PHP, mostly because there are huge reference books she can read and > follow. I suggest "Core PHP", but then that's because I was technical editor ;) > (It's unfortunate that there are no nice Python solutions I > can teach h

Re: [Web-SIG] JavaScript escape function

2005-04-25 Thread Donovan Preston
On Apr 25, 2005, at 9:23 PM, Rene Dudfield wrote:repr works quite well, and I've used it with lots of different _javascript_... However I'm not completely confident in it as it fails for unicode.Ah, unicode, yes. Nevow handles unicode at a different abstraction level, in the main flatten loop, nevo

Re: [Web-SIG] JavaScript escape function

2005-04-25 Thread Rene Dudfield
repr works quite well, and I've used it with lots of different javascript... However I'm not completely confident in it as it fails for unicode. eg. >>> a = u'a=\'asdfd\';\n\r\n' >>> a u"a='asdfd';\n\r\n" >>> print repr(a) u"a='asdfd';\n\r\n" This is an invalid js string. eek. So first we need

Re: [Web-SIG] JavaScript escape function

2005-04-25 Thread Donovan Preston
On Apr 25, 2005, at 7:34 PM, Ian Bicking wrote: Donovan Preston wrote: var s = '$jquote($s)' Leaving it up to the developer to ensure every potentially unsafe python string is quoted properly always makes me nervous. Nevow has enough information to automatically safely quote strings inserte

Re: [Web-SIG] JavaScript escape function

2005-04-25 Thread Ian Bicking
Donovan Preston wrote: var s = '$jquote($s)' Leaving it up to the developer to ensure every potentially unsafe python string is quoted properly always makes me nervous. Nevow has enough information to automatically safely quote strings inserted in html, html attribute, and URL contexts, but i

Re: [Web-SIG] JavaScript escape function

2005-04-25 Thread Donovan Preston
On Apr 26, 2005, at 1:19 AM, Jp Calderone wrote: Nevow has liveevil.jquote(), which I believe does what you want. It is strikingly simple and straightforward: def jquote(jscript): return jscript.replace('\\', '' ).replace("'", "\\'" ).replace('\n', '\\n') I

Re: [Web-SIG] JavaScript escape function

2005-04-25 Thread Jp Calderone
On Mon, 25 Apr 2005 18:11:46 -0700, Shannon -jj Behrens <[EMAIL PROTECTED]> wrote: Hey guys, I need a JavaScript escape function. Let's say I have a variable, and I'm generating some JavaScript from Cheetah: var s = "$s"; I need to make $s safe: var s = "$javascript_safe($s)"; Has anyone cod

Re: [Web-SIG] JavaScript escape function

2005-04-25 Thread Ian Bicking
Shannon -jj Behrens wrote: Hey guys, I need a JavaScript escape function. Let's say I have a variable, and I'm generating some JavaScript from Cheetah: var s = "$s"; I need to make $s safe: var s = "$javascript_safe($s)"; Has anyone coded this yet? Will the same function work for both sin