Merge lp:~zorba-coders/zorba/bug-932884-xhtml-serialization into lp:zorba

Proposed by Chris Hillery
Status: Merged
Approved by: Matthias Brantner
Approved revision: 11014
Merged at revision: 11015
Proposed branch: lp:~zorba-coders/zorba/bug-932884-xhtml-serialization
Merge into: lp:zorba
Diff against target: 211 lines (+58/-38)
15 files modified
ChangeLog (+1/-0)
src/api/serialization/serializer.cpp (+6/-38)
test/rbkt/ExpQueryResults/zorba/serialization/html/empty-1.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/serialization/html/empty-2.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/serialization/xhtml/empty-1.xml.res (+1/-0)
test/rbkt/ExpQueryResults/zorba/serialization/xhtml/empty-2.xml.res (+1/-0)
test/rbkt/Queries/zorba/serialization/html/empty-1.spec (+1/-0)
test/rbkt/Queries/zorba/serialization/html/empty-1.xq (+14/-0)
test/rbkt/Queries/zorba/serialization/html/empty-2.spec (+1/-0)
test/rbkt/Queries/zorba/serialization/html/empty-2.xq (+4/-0)
test/rbkt/Queries/zorba/serialization/xhtml/empty-1.spec (+1/-0)
test/rbkt/Queries/zorba/serialization/xhtml/empty-1.xq (+14/-0)
test/rbkt/Queries/zorba/serialization/xhtml/empty-2.spec (+1/-0)
test/rbkt/Queries/zorba/serialization/xhtml/empty-2.xq (+4/-0)
test/rbkt/testdriver.cpp (+7/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/bug-932884-xhtml-serialization
Reviewer Review Type Date Requested Status
Matthias Brantner Approve
Chris Hillery Approve
Review via email: mp+122156@code.launchpad.net

Commit message

Corrected HTML serialization of empty elements. Added test cases for XHTML.

To post a comment you must log in.
Revision history for this message
Chris Hillery (ceejatec) wrote :

Matthias - you initially raised the issue about <iframe> serialization. If you could confirm that this change fixes that, and ideally doesn't break anything else, that'd be great.

Revision history for this message
Chris Hillery (ceejatec) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug-932884-xhtml-serialization-2012-08-30T21-42-53.199Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1. Got: 1 Approve, 1 Pending.

Revision history for this message
William Candillon (wcandillon) wrote :

Works great on two examples that used to be buggy.

Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug-932884-xhtml-serialization-2012-08-31T14-56-55.077Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2012-08-30 15:14:16 +0000
3+++ ChangeLog 2012-08-30 21:39:21 +0000
4@@ -21,6 +21,7 @@
5 * Fixed bug #1039488 (inserting more than one pair at once in a JSON object)
6 * Fixed bug #1042840 (qname pool free-list corruption)
7 * Fixed bug #866984 (better error message for an eval error)
8+ * Fixed bug #932884 (HTML and XHTML serialization of empty elements)
9
10 version 2.6
11
12
13=== modified file 'src/api/serialization/serializer.cpp'
14--- src/api/serialization/serializer.cpp 2012-08-30 13:45:43 +0000
15+++ src/api/serialization/serializer.cpp 2012-08-30 21:39:21 +0000
16@@ -1368,28 +1368,6 @@
17
18
19 /*******************************************************************************
20- Returns true for those elements which are not allowed under HTML to have
21- empty tags (more exactly they are required to have both opening and closing
22- tags).
23-********************************************************************************/
24-static bool is_html_no_empty_tags_element(const store::Item* item)
25-{
26- if (item == NULL)
27- return false;
28-
29- zstring nodename;
30- utf8::to_lower(item->getNodeName()->getStringValue(), &nodename);
31-
32- if (ztd::equals(nodename, "script", 6) ||
33- ztd::equals(nodename, "textarea", 8) ||
34- ztd::equals(nodename, "div", 3))
35- return true;
36- else
37- return false;
38-}
39-
40-
41-/*******************************************************************************
42
43 ********************************************************************************/
44 static bool is_html_boolean_attribute(const zstring& attribute)
45@@ -1569,27 +1547,17 @@
46 }
47 else
48 {
49- // The HTML 4.01 spec says that both tags (begin and end tags) are REQUIRED
50- // for script, textarea and div tags.
51- if (is_html_no_empty_tags_element(item) ||
52- (ser->include_content_type == PARAMETER_VALUE_YES &&
53- strcasecmp(qname.c_str(), "head") == 0))
54+ // The HTML 4.01 and XQuery Serialization specs strongly imply that
55+ // ALL empty elements must be serialized as either a matched open-
56+ // close tag, or (only for elements with an empty content model) as
57+ // an unclosed open tag.
58+ if (is_html_empty_content_model_element(item))
59 {
60 tr << ">";
61- tr << "</" << qname << ">";
62 }
63 else
64 {
65- // The HTML output method MUST NOT output an end-tag for empty elements.
66- // For HTML 4.0, the empty elements are area, base, basefont, br, col,
67- // frame, hr, img, input, isindex, link, meta and param. For example,
68- // an element written as <br/> or <br></br> in an XSLT stylesheet MUST
69- // be output as <br>.
70- if (is_html_empty_content_model_element(item) &&
71- ser->version == PARAMETER_VALUE_VERSION_4_0)
72- tr << ">";
73- else
74- tr << "/>";
75+ tr << "></" << qname << ">";
76 }
77 }
78
79
80=== added directory 'test/rbkt/ExpQueryResults/zorba/serialization/html'
81=== added file 'test/rbkt/ExpQueryResults/zorba/serialization/html/empty-1.xml.res'
82--- test/rbkt/ExpQueryResults/zorba/serialization/html/empty-1.xml.res 1970-01-01 00:00:00 +0000
83+++ test/rbkt/ExpQueryResults/zorba/serialization/html/empty-1.xml.res 2012-08-30 21:39:21 +0000
84@@ -0,0 +1,1 @@
85+<body><area><base><br><col><hr><img src="http://www.zorba-xquery.com"><input><link><meta><param name="a" value="1"></body>
86\ No newline at end of file
87
88=== added file 'test/rbkt/ExpQueryResults/zorba/serialization/html/empty-2.xml.res'
89--- test/rbkt/ExpQueryResults/zorba/serialization/html/empty-2.xml.res 1970-01-01 00:00:00 +0000
90+++ test/rbkt/ExpQueryResults/zorba/serialization/html/empty-2.xml.res 2012-08-30 21:39:21 +0000
91@@ -0,0 +1,1 @@
92+<body><p></p><textarea></textarea><td></td><iframe></iframe><div></div><script></script></body>
93\ No newline at end of file
94
95=== added directory 'test/rbkt/ExpQueryResults/zorba/serialization/xhtml'
96=== added file 'test/rbkt/ExpQueryResults/zorba/serialization/xhtml/empty-1.xml.res'
97--- test/rbkt/ExpQueryResults/zorba/serialization/xhtml/empty-1.xml.res 1970-01-01 00:00:00 +0000
98+++ test/rbkt/ExpQueryResults/zorba/serialization/xhtml/empty-1.xml.res 2012-08-30 21:39:21 +0000
99@@ -0,0 +1,1 @@
100+<body><area /><base /><br /><col /><hr /><img src="http://www.zorba-xquery.com" /><input /><link /><meta /><param name="a" value="1" /></body>
101\ No newline at end of file
102
103=== added file 'test/rbkt/ExpQueryResults/zorba/serialization/xhtml/empty-2.xml.res'
104--- test/rbkt/ExpQueryResults/zorba/serialization/xhtml/empty-2.xml.res 1970-01-01 00:00:00 +0000
105+++ test/rbkt/ExpQueryResults/zorba/serialization/xhtml/empty-2.xml.res 2012-08-30 21:39:21 +0000
106@@ -0,0 +1,1 @@
107+<body><p></p><textarea></textarea><td></td><iframe></iframe><div></div><random></random></body>
108\ No newline at end of file
109
110=== added directory 'test/rbkt/Queries/zorba/serialization/html'
111=== added file 'test/rbkt/Queries/zorba/serialization/html/empty-1.spec'
112--- test/rbkt/Queries/zorba/serialization/html/empty-1.spec 1970-01-01 00:00:00 +0000
113+++ test/rbkt/Queries/zorba/serialization/html/empty-1.spec 2012-08-30 21:39:21 +0000
114@@ -0,0 +1,1 @@
115+Serialization: method=html
116
117=== added file 'test/rbkt/Queries/zorba/serialization/html/empty-1.xq'
118--- test/rbkt/Queries/zorba/serialization/html/empty-1.xq 1970-01-01 00:00:00 +0000
119+++ test/rbkt/Queries/zorba/serialization/html/empty-1.xq 2012-08-30 21:39:21 +0000
120@@ -0,0 +1,14 @@
121+(: Ensure tags that have an empty content mode in HTML are :)
122+(: serialized correctly :)
123+<body>
124+<area/>
125+<base/>
126+<br/>
127+<col/>
128+<hr/>
129+<img src="http://www.zorba-xquery.com"/>
130+<input/>
131+<link/>
132+<meta/>
133+<param name="a" value="1"/>
134+</body>
135\ No newline at end of file
136
137=== added file 'test/rbkt/Queries/zorba/serialization/html/empty-2.spec'
138--- test/rbkt/Queries/zorba/serialization/html/empty-2.spec 1970-01-01 00:00:00 +0000
139+++ test/rbkt/Queries/zorba/serialization/html/empty-2.spec 2012-08-30 21:39:21 +0000
140@@ -0,0 +1,1 @@
141+Serialization: method=html
142
143=== added file 'test/rbkt/Queries/zorba/serialization/html/empty-2.xq'
144--- test/rbkt/Queries/zorba/serialization/html/empty-2.xq 1970-01-01 00:00:00 +0000
145+++ test/rbkt/Queries/zorba/serialization/html/empty-2.xq 2012-08-30 21:39:21 +0000
146@@ -0,0 +1,4 @@
147+(: Ensure tags that MAY be empty in HTML are serialized correctly :)
148+<body>
149+<p/><textarea/><td/><iframe/><div/><script/>
150+</body>
151\ No newline at end of file
152
153=== added directory 'test/rbkt/Queries/zorba/serialization/xhtml'
154=== added file 'test/rbkt/Queries/zorba/serialization/xhtml/empty-1.spec'
155--- test/rbkt/Queries/zorba/serialization/xhtml/empty-1.spec 1970-01-01 00:00:00 +0000
156+++ test/rbkt/Queries/zorba/serialization/xhtml/empty-1.spec 2012-08-30 21:39:21 +0000
157@@ -0,0 +1,1 @@
158+Serialization: method=xhtml
159
160=== added file 'test/rbkt/Queries/zorba/serialization/xhtml/empty-1.xq'
161--- test/rbkt/Queries/zorba/serialization/xhtml/empty-1.xq 1970-01-01 00:00:00 +0000
162+++ test/rbkt/Queries/zorba/serialization/xhtml/empty-1.xq 2012-08-30 21:39:21 +0000
163@@ -0,0 +1,14 @@
164+(: Ensure tags that have an empty content model in XHTML are :)
165+(: serialized correctly :)
166+<body>
167+<area/>
168+<base/>
169+<br/>
170+<col/>
171+<hr/>
172+<img src="http://www.zorba-xquery.com"/>
173+<input/>
174+<link/>
175+<meta/>
176+<param name="a" value="1"/>
177+</body>
178
179=== added file 'test/rbkt/Queries/zorba/serialization/xhtml/empty-2.spec'
180--- test/rbkt/Queries/zorba/serialization/xhtml/empty-2.spec 1970-01-01 00:00:00 +0000
181+++ test/rbkt/Queries/zorba/serialization/xhtml/empty-2.spec 2012-08-30 21:39:21 +0000
182@@ -0,0 +1,1 @@
183+Serialization: method=xhtml
184
185=== added file 'test/rbkt/Queries/zorba/serialization/xhtml/empty-2.xq'
186--- test/rbkt/Queries/zorba/serialization/xhtml/empty-2.xq 1970-01-01 00:00:00 +0000
187+++ test/rbkt/Queries/zorba/serialization/xhtml/empty-2.xq 2012-08-30 21:39:21 +0000
188@@ -0,0 +1,4 @@
189+(: Ensure tags that MAY be empty in XHTML are serialized correctly :)
190+<body>
191+<p/><textarea/><td/><iframe/><div/><random/>
192+</body>
193\ No newline at end of file
194
195=== modified file 'test/rbkt/testdriver.cpp'
196--- test/rbkt/testdriver.cpp 2012-08-30 13:45:43 +0000
197+++ test/rbkt/testdriver.cpp 2012-08-30 21:39:21 +0000
198@@ -542,6 +542,13 @@
199 std::cout << "testdriver: skipping canonicalization "
200 "when testing with indent==yes" << std::endl;
201 }
202+ // Also skip canonicalization for tests using method==xhtml or html
203+ // (so we can test for correct serialization of empty elements)
204+ else if (lSerOptions.ser_method == ZORBA_SERIALIZATION_METHOD_XHTML ||
205+ lSerOptions.ser_method == ZORBA_SERIALIZATION_METHOD_HTML) {
206+ std::cout << "testdriver: skipping canonicalization "
207+ "when testing with method=[x]html" << std::endl;
208+ }
209 #ifdef ZORBA_WITH_JSON
210 // Also skip canonicalization for tests using method==json
211 else if (lSerOptions.ser_method == ZORBA_SERIALIZATION_METHOD_JSON) {

Subscribers

People subscribed via source and target branches