[Zope3-checkins] SVN: Zope3/trunk/src/ fix issue 644 by changing our local copy of ClientForm, the change will be

Benji York benji at zope.com
Tue Jul 18 10:05:48 EDT 2006


Log message for revision 69171:
  fix issue 644 by changing our local copy of ClientForm, the change will be
  submitted to the upstream project.
  

Changed:
  U   Zope3/trunk/src/ClientForm.py
  U   Zope3/trunk/src/zope/testbrowser/README.txt
  U   Zope3/trunk/src/zope/testbrowser/tests.py

-=-
Modified: Zope3/trunk/src/ClientForm.py
===================================================================
--- Zope3/trunk/src/ClientForm.py	2006-07-18 11:30:39 UTC (rev 69170)
+++ Zope3/trunk/src/ClientForm.py	2006-07-18 14:05:47 UTC (rev 69171)
@@ -642,6 +642,12 @@
                 d["__label"] = self._current_label
 
     def handle_data(self, data):
+        # according to http://www.w3.org/TR/html4/appendix/notes.html#h-B.3.1
+        # linebreaks immediately after start tags or immediately before end
+        # tags must be ignored, but real browsers only ignore a
+        if data[0:1] == '\n':
+            data = data[1:]
+
         debug("%s", data)
         if self._option is not None:
             # self._option is a dictionary of the OPTION element's HTML

Modified: Zope3/trunk/src/zope/testbrowser/README.txt
===================================================================
--- Zope3/trunk/src/zope/testbrowser/README.txt	2006-07-18 11:30:39 UTC (rev 69170)
+++ Zope3/trunk/src/zope/testbrowser/README.txt	2006-07-18 14:05:47 UTC (rev 69171)
@@ -621,7 +621,7 @@
     >>> verifyObject(interfaces.IControl, ctrl)
     True
     >>> ctrl.value
-    '\n        Text inside\n        area!\n      '
+    '        Text inside\n        area!\n      '
     >>> ctrl.value = 'A lot of\n text.'
     >>> ctrl.disabled
     False

Modified: Zope3/trunk/src/zope/testbrowser/tests.py
===================================================================
--- Zope3/trunk/src/zope/testbrowser/tests.py	2006-07-18 11:30:39 UTC (rev 69170)
+++ Zope3/trunk/src/zope/testbrowser/tests.py	2006-07-18 14:05:47 UTC (rev 69171)
@@ -218,6 +218,66 @@
 
     """
 
+
+def test_strip_linebreaks_from_textarea(self):
+    """
+
+    >>> browser = Browser()
+
+According to http://www.w3.org/TR/html4/appendix/notes.html#h-B.3.1 line break
+immediately after start tags or immediately before end tags must be ignored,
+but real browsers only ignore a line break after a start tag.  So if we give
+the following form:
+
+    >>> browser.open('''
+    ... <html><body>
+    ...   <form action="." method="post" enctype="multipart/form-data">
+    ...      <textarea name="textarea">
+    ... Foo
+    ... </textarea>
+    ...   </form></body></html>
+    ... ''') # doctest: +ELLIPSIS
+    GET / HTTP/1.1
+    ...
+
+The value of the textarea won't contain the first line break:
+
+    >>> browser.getControl(name='textarea').value
+    'Foo\\n'
+
+Of course, if we add line breaks, so that there are now two line breaks
+after the start tag, the textarea value will start and end with a line break.
+
+    >>> browser.open('''
+    ... <html><body>
+    ...   <form action="." method="post" enctype="multipart/form-data">
+    ...      <textarea name="textarea">
+    ...
+    ... Foo
+    ... </textarea>
+    ...   </form></body></html>
+    ... ''') # doctest: +ELLIPSIS
+    GET / HTTP/1.1
+    ...
+
+    >>> browser.getControl(name='textarea').value
+    '\\nFoo\\n'
+
+Also, if there is some other whitespace after the start tag, it will be preserved.
+
+    >>> browser.open('''
+    ... <html><body>
+    ...   <form action="." method="post" enctype="multipart/form-data">
+    ...      <textarea name="textarea">  Foo  </textarea>
+    ...   </form></body></html>
+    ... ''') # doctest: +ELLIPSIS
+    GET / HTTP/1.1
+    ...
+
+    >>> browser.getControl(name='textarea').value
+    '  Foo  '
+    """
+
 checker = renormalizing.RENormalizing([
     (re.compile(r'^--\S+\.\S+\.\S+', re.M), '-'*30),
     (re.compile(r'boundary=\S+\.\S+\.\S+'), 'boundary='+'-'*30),



More information about the Zope3-Checkins mailing list