[Twisted-Python] Small diff for LivePage controller

Bill Gribble grib at billgribble.com
Tue May 27 10:38:21 EDT 2003


Hi.  I noticed that when my LivePage instance sends updates to DOM
elements that are whitespace-sensitive, such as <pre> and 
<textarea wordwrap="off>, embedded newlines were getting stripped,
leaving the element bodies as single text lines with some interword
spacing removed. 

I tracked the problem down to this bit of code in woven/controller.py. 
The Javascript code generator is formatting the new element as a literal
Javascript string which will be processed on the client side to modify
the page.  But by stripping out the newlines in the code we remove some
important information in some HTML contexts.  

This patch leaves embedded newlines in the text, using JavaScript
literal string escapes to make sure they get passed through OK.  I also
added string escaping for other legal special characters that have 
JS literal escapes. 

With this patch, LivePage is working really well for me!  Thanks to all
the folks who have given help on IRC.  FWIW this patch is in the public
domain. 

Bill Gribble


Index: controller.py
===================================================================
RCS file: /cvs/Twisted/twisted/web/woven/controller.py,v
retrieving revision 1.60
diff -r1.60 controller.py
368,369d367
<             nodeXML = nodeXML.replace('\n', '')
<             nodeXML = nodeXML.replace('\r', '')
371a370,378
>             nodeXML = nodeXML.replace('"', '\\"')
>             nodeXML = nodeXML.replace('\n', '\\n')
>             nodeXML = nodeXML.replace('\r', '\\r')
>             nodeXML = nodeXML.replace('\b', '\\b')
>             nodeXML = nodeXML.replace('\t', '\\t')
>             nodeXML = nodeXML.replace('\000', '\\0')
>             nodeXML = nodeXML.replace('\v', '\\v')
>             nodeXML = nodeXML.replace('\f', '\\f')
> 



-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20030527/017a0716/attachment.pgp 


More information about the Twisted-Python mailing list