Chris Hillery has proposed merging 
lp:~zorba-coders/zorba/bug-932884-xhtml-serialization into lp:zorba.

Requested reviews:
  Matthias Brantner (matthias-brantner)
Related bugs:
  Bug #932884 in Zorba: "empty tags in XHTML serialization"
  https://bugs.launchpad.net/zorba/+bug/932884

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug-932884-xhtml-serialization/+merge/122156
-- 
https://code.launchpad.net/~zorba-coders/zorba/bug-932884-xhtml-serialization/+merge/122156
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog	2012-08-30 15:14:16 +0000
+++ ChangeLog	2012-08-30 21:39:21 +0000
@@ -21,6 +21,7 @@
   * Fixed bug #1039488 (inserting more than one pair at once in a JSON object)
   * Fixed bug #1042840 (qname pool free-list corruption)
   * Fixed bug #866984 (better error message for an eval error)
+  * Fixed bug #932884 (HTML and XHTML serialization of empty elements)
 	
 version 2.6
 

=== modified file 'src/api/serialization/serializer.cpp'
--- src/api/serialization/serializer.cpp	2012-08-30 13:45:43 +0000
+++ src/api/serialization/serializer.cpp	2012-08-30 21:39:21 +0000
@@ -1368,28 +1368,6 @@
 
 
 /*******************************************************************************
-  Returns true for those elements which are not allowed under HTML to have
-  empty tags (more exactly they are required to have both opening and closing
-  tags).
-********************************************************************************/
-static bool is_html_no_empty_tags_element(const store::Item* item)
-{
-  if (item == NULL)
-    return false;
-
-  zstring nodename;
-  utf8::to_lower(item->getNodeName()->getStringValue(), &nodename);
-
-  if (ztd::equals(nodename, "script", 6) ||
-      ztd::equals(nodename, "textarea", 8) ||
-      ztd::equals(nodename, "div", 3))
-    return true;
-  else
-    return false;
-}
-
-
-/*******************************************************************************
 
 ********************************************************************************/
 static bool is_html_boolean_attribute(const zstring& attribute)
@@ -1569,27 +1547,17 @@
     }
     else
     {
-      // The HTML 4.01 spec says that both tags (begin and end tags) are REQUIRED
-      // for script, textarea and div tags.
-      if (is_html_no_empty_tags_element(item) ||
-          (ser->include_content_type == PARAMETER_VALUE_YES &&
-           strcasecmp(qname.c_str(), "head") == 0))
+      // The HTML 4.01 and XQuery Serialization specs strongly imply that
+      // ALL empty elements must be serialized as either a matched open-
+      // close tag, or (only for elements with an empty content model) as
+      // an unclosed open tag.
+      if (is_html_empty_content_model_element(item))
       {
         tr << ">";
-        tr << "</" << qname << ">";
       }
       else
       {
-        // The HTML output method MUST NOT output an end-tag for empty elements.
-        // For HTML 4.0, the empty elements are area, base, basefont, br, col,
-        // frame, hr, img, input, isindex, link, meta and param. For example,
-        // an element written as <br/> or <br></br> in an XSLT stylesheet MUST
-        // be output as <br>.
-        if (is_html_empty_content_model_element(item) &&
-            ser->version == PARAMETER_VALUE_VERSION_4_0)
-          tr << ">";
-        else
-          tr << "/>";
+        tr << "></" << qname << ">";
       }
     }
 

=== added directory 'test/rbkt/ExpQueryResults/zorba/serialization/html'
=== added file 'test/rbkt/ExpQueryResults/zorba/serialization/html/empty-1.xml.res'
--- test/rbkt/ExpQueryResults/zorba/serialization/html/empty-1.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/serialization/html/empty-1.xml.res	2012-08-30 21:39:21 +0000
@@ -0,0 +1,1 @@
+<body><area><base><br><col><hr><img src="http://www.zorba-xquery.com";><input><link><meta><param name="a" value="1"></body>
\ No newline at end of file

=== added file 'test/rbkt/ExpQueryResults/zorba/serialization/html/empty-2.xml.res'
--- test/rbkt/ExpQueryResults/zorba/serialization/html/empty-2.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/serialization/html/empty-2.xml.res	2012-08-30 21:39:21 +0000
@@ -0,0 +1,1 @@
+<body><p></p><textarea></textarea><td></td><iframe></iframe><div></div><script></script></body>
\ No newline at end of file

=== added directory 'test/rbkt/ExpQueryResults/zorba/serialization/xhtml'
=== added file 'test/rbkt/ExpQueryResults/zorba/serialization/xhtml/empty-1.xml.res'
--- test/rbkt/ExpQueryResults/zorba/serialization/xhtml/empty-1.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/serialization/xhtml/empty-1.xml.res	2012-08-30 21:39:21 +0000
@@ -0,0 +1,1 @@
+<body><area /><base /><br /><col /><hr /><img src="http://www.zorba-xquery.com"; /><input /><link /><meta /><param name="a" value="1" /></body>
\ No newline at end of file

=== added file 'test/rbkt/ExpQueryResults/zorba/serialization/xhtml/empty-2.xml.res'
--- test/rbkt/ExpQueryResults/zorba/serialization/xhtml/empty-2.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/serialization/xhtml/empty-2.xml.res	2012-08-30 21:39:21 +0000
@@ -0,0 +1,1 @@
+<body><p></p><textarea></textarea><td></td><iframe></iframe><div></div><random></random></body>
\ No newline at end of file

=== added directory 'test/rbkt/Queries/zorba/serialization/html'
=== added file 'test/rbkt/Queries/zorba/serialization/html/empty-1.spec'
--- test/rbkt/Queries/zorba/serialization/html/empty-1.spec	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/serialization/html/empty-1.spec	2012-08-30 21:39:21 +0000
@@ -0,0 +1,1 @@
+Serialization: method=html

=== added file 'test/rbkt/Queries/zorba/serialization/html/empty-1.xq'
--- test/rbkt/Queries/zorba/serialization/html/empty-1.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/serialization/html/empty-1.xq	2012-08-30 21:39:21 +0000
@@ -0,0 +1,14 @@
+(: Ensure tags that have an empty content mode in HTML are :)
+(: serialized correctly :)
+<body>
+<area/>
+<base/>
+<br/>
+<col/>
+<hr/>
+<img src="http://www.zorba-xquery.com"/>
+<input/>
+<link/>
+<meta/>
+<param name="a" value="1"/>
+</body>
\ No newline at end of file

=== added file 'test/rbkt/Queries/zorba/serialization/html/empty-2.spec'
--- test/rbkt/Queries/zorba/serialization/html/empty-2.spec	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/serialization/html/empty-2.spec	2012-08-30 21:39:21 +0000
@@ -0,0 +1,1 @@
+Serialization: method=html

=== added file 'test/rbkt/Queries/zorba/serialization/html/empty-2.xq'
--- test/rbkt/Queries/zorba/serialization/html/empty-2.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/serialization/html/empty-2.xq	2012-08-30 21:39:21 +0000
@@ -0,0 +1,4 @@
+(: Ensure tags that MAY be empty in HTML are serialized correctly :)
+<body>
+<p/><textarea/><td/><iframe/><div/><script/>
+</body>
\ No newline at end of file

=== added directory 'test/rbkt/Queries/zorba/serialization/xhtml'
=== added file 'test/rbkt/Queries/zorba/serialization/xhtml/empty-1.spec'
--- test/rbkt/Queries/zorba/serialization/xhtml/empty-1.spec	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/serialization/xhtml/empty-1.spec	2012-08-30 21:39:21 +0000
@@ -0,0 +1,1 @@
+Serialization: method=xhtml

=== added file 'test/rbkt/Queries/zorba/serialization/xhtml/empty-1.xq'
--- test/rbkt/Queries/zorba/serialization/xhtml/empty-1.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/serialization/xhtml/empty-1.xq	2012-08-30 21:39:21 +0000
@@ -0,0 +1,14 @@
+(: Ensure tags that have an empty content model in XHTML are :)
+(: serialized correctly :)
+<body>
+<area/>
+<base/>
+<br/>
+<col/>
+<hr/>
+<img src="http://www.zorba-xquery.com"/>
+<input/>
+<link/>
+<meta/>
+<param name="a" value="1"/>
+</body>

=== added file 'test/rbkt/Queries/zorba/serialization/xhtml/empty-2.spec'
--- test/rbkt/Queries/zorba/serialization/xhtml/empty-2.spec	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/serialization/xhtml/empty-2.spec	2012-08-30 21:39:21 +0000
@@ -0,0 +1,1 @@
+Serialization: method=xhtml

=== added file 'test/rbkt/Queries/zorba/serialization/xhtml/empty-2.xq'
--- test/rbkt/Queries/zorba/serialization/xhtml/empty-2.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/serialization/xhtml/empty-2.xq	2012-08-30 21:39:21 +0000
@@ -0,0 +1,4 @@
+(: Ensure tags that MAY be empty in XHTML are serialized correctly :)
+<body>
+<p/><textarea/><td/><iframe/><div/><random/>
+</body>
\ No newline at end of file

=== modified file 'test/rbkt/testdriver.cpp'
--- test/rbkt/testdriver.cpp	2012-08-30 13:45:43 +0000
+++ test/rbkt/testdriver.cpp	2012-08-30 21:39:21 +0000
@@ -542,6 +542,13 @@
           std::cout << "testdriver: skipping canonicalization "
             "when testing with indent==yes" << std::endl;
         }
+        // Also skip canonicalization for tests using method==xhtml or html
+        // (so we can test for correct serialization of empty elements)
+        else if (lSerOptions.ser_method == ZORBA_SERIALIZATION_METHOD_XHTML ||
+                 lSerOptions.ser_method == ZORBA_SERIALIZATION_METHOD_HTML) {
+          std::cout << "testdriver: skipping canonicalization "
+            "when testing with method=[x]html" << std::endl;
+        }
 #ifdef ZORBA_WITH_JSON
         // Also skip canonicalization for tests using method==json
         else if (lSerOptions.ser_method == ZORBA_SERIALIZATION_METHOD_JSON) {

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to