Changeset 95
- Timestamp:
- 01/27/2007 12:03:07 (22 months ago)
- Location:
- trunk
- Files:
-
- 4 modified
-
ext/hpricot_scan/hpricot_scan.rl (modified) (2 diffs)
-
lib/hpricot/parse.rb (modified) (5 diffs)
-
test/test_parser.rb (modified) (1 diff)
-
test/test_preserved.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ext/hpricot_scan/hpricot_scan.rl
r85 r95 18 18 #define ELE(N) \ 19 19 if (tokend > tokstart || text == 1) { \ 20 ele_open = 0; \ 21 rb_yield_tokens(sym_##N, tag, attr, tokstart == 0 ? Qnil : rb_str_new(tokstart, tokend-tokstart), taint); \ 20 VALUE raw_string = Qnil; \ 21 ele_open = 0; text = 0; \ 22 if (tokstart != 0 && sym_##N != sym_cdata && sym_##N != sym_text && sym_##N != sym_procins && sym_##N != sym_comment) { \ 23 raw_string = rb_str_new(tokstart, tokend-tokstart); \ 24 } \ 25 rb_yield_tokens(sym_##N, tag, attr, raw_string, taint); \ 22 26 } 23 27 … … 54 58 } 55 59 56 #define EBLK(N, T) CAT(tag, p - T + 1); ELE(N); text = 0;60 #define EBLK(N, T) CAT(tag, p - T + 1); ELE(N); 57 61 58 62 %%{ -
trunk/lib/hpricot/parse.rb
r94 r95 206 206 def Text.parse_pcdata(raw_string) 207 207 result = Text.new(raw_string) 208 result.raw_string = raw_string209 208 result 210 209 end … … 212 211 def Text.parse_cdata_content(raw_string) 213 212 result = CData.new(raw_string) 214 result.raw_string = raw_string215 213 result 216 214 end … … 218 216 def Text.parse_cdata_section(content) 219 217 result = CData.new(content) 220 result.raw_string = content221 218 result 222 219 end … … 256 253 _, target, content = *raw_string.match(/\A<\?(\S+)\s+(.+)/m) 257 254 result = ProcIns.new(target, content) 258 result.raw_string = "#{raw_string}?>"259 255 result 260 256 end … … 262 258 def Comment.parse(content) 263 259 result = Comment.new(content) 264 result.raw_string = "<!--" + content.to_s + "-->"265 260 result 266 261 end -
trunk/test/test_parser.rb
r94 r95 48 48 49 49 def scan_basic doc 50 assert_kind_of Hpricot::XMLDecl, doc.children.first 51 assert_not_equal doc.children.first.to_s, doc.children[1].to_s 50 52 assert_equal 'link1', doc.at('#link1')['id'] 51 53 assert_equal 'link1', doc.at("p a")['id'] -
trunk/test/test_preserved.rb
r83 r95 3 3 require 'test/unit' 4 4 require 'hpricot' 5 require 'load_files' 5 6 6 7 class TestPreserved < Test::Unit::TestCase 8 def assert_roundtrip str 9 doc = Hpricot(str) 10 yield doc if block_given? 11 str2 = doc.to_original_html 12 [*str].zip([*str2]).each do |s1, s2| 13 assert_equal s1, s2 14 end 15 end 16 7 17 def assert_html str1, str2 8 18 doc = Hpricot(str2) … … 29 39 end 30 40 41 def test_files 42 assert_roundtrip TestFiles::BASIC 43 assert_roundtrip TestFiles::BOINGBOING 44 end 31 45 end
