public this repo is viewable by everyone
Description: Yet Another Planet Refactoring
Homepage: http://intertwingly.net/blog/2007/12/19/Yet-Another-Planet-Refactoring
Clone URL: git://github.com/rubys/mars.git
Add test cases, and explicitly close non-void elements
Sam Ruby (author)
about 1 month ago
commit  594cd30192668c6310b3236b978d5d4a6d706fb7
tree    fb2c98375a3f69e66dc22da049a8c7e26438d717
parent  775bc2a397c7812ae67b9979f288c3c835aab059
...
112
113
114
115
116
 
117
118
119
120
121
122
123
 
124
125
126
...
112
113
114
 
 
115
116
 
 
 
 
 
 
117
118
119
120
0
@@ -112,15 +112,9 @@ module Planet
0
   include HTML5::HTMLSanitizeModule
0
   @sanitizer = HTML5::HTMLSanitizer.new ''
0
   def Planet.sanitize node, fido
0
- # cull empty formatting elements. They can cause FF & Konq to nest badly.
0
- # For instance, <i/> causes everything after it to italicized, including other entries.
0
+ # ensure that non-void elements don't use XML's empty element syntax
0
     if node.elements.size == 0 && node.text == nil
0
- if %w{abbr acronym b big cite code del dfn em i ins kbd s
0
- samp small strike strong sub sup tt u var}.include? node.name
0
- # If the node has no children and no text, it can only cause trouble.
0
- node.remove
0
- return
0
- end
0
+ node.text = '' unless HTML5::VOID_ELEMENTS.include? node.name
0
     end
0
 
0
     node.elements.each {|child| sanitize child, fido}
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
0
@@ -0,0 +1,14 @@
0
+require 'test/unit'
0
+require 'planet/sift'
0
+
0
+class SiftTestCase < Test::Unit::TestCase
0
+ ATOMNS = 'xmlns="http://www.w3.org/2005/Atom"'
0
+
0
+ def test_empty_formatting_elements
0
+ # http://github.com/bronson/mars/commit/775bc2a397c7812ae67b9979f288c3c835aab059
0
+ title = "<title type='html' #{ATOMNS}>&lt;i/&gt;</title>"
0
+ doc = Planet::XmlParser.parse(title)
0
+ Planet.sift doc, nil
0
+ assert_equal '<i></i>', doc.elements['title/div'].to_a.join
0
+ end
0
+end
...
15
16
17
 
 
 
 
 
 
18
...
15
16
17
18
19
20
21
22
23
24
0
@@ -15,4 +15,10 @@ class XmlParserTestCase < Test::Unit::TestCase
0
     doc = Planet::XmlParser.parse('<e a="&amp;"/>')
0
     assert_nil doc.to_s.index('&amp;amp;')
0
   end
0
+
0
+ def test_bozo
0
+ # http://github.com/bronson/mars/commit/567e2f3f459d446f0530bbd4c8acb00dde378420
0
+ doc = Planet::XmlParser.parse('<e a="&amp;">')
0
+ assert doc.bozo
0
+ end
0
 end

Comments

    No one has commented yet.