Ticket #131: rexml19.diff
| File rexml19.diff, 23.5 kB (added by rubys, 18 months ago) |
|---|
-
test/xpath_test.rb
335 335 fail "'bar' should match nothing in this case" 336 336 } 337 337 338 namespace = {"t" ,"this"}338 namespace = {"t"=>"this"} 339 339 results = XPath.first( doc, "//t:bar", namespace ) 340 340 assert_equal "this bar", results.text 341 341 end … … 937 937 sum = Document.new(File.new("test/yahoo.xml")).elements.to_a("//item").size 938 938 assert_equal( 10, sum ) 939 939 940 text = Document.new(File.new("test/yahoo.xml")).elements.to_a(%Q{//title[contains(text(), "'")]}).collect{|e| e.text}. to_s940 text = Document.new(File.new("test/yahoo.xml")).elements.to_a(%Q{//title[contains(text(), "'")]}).collect{|e| e.text}.join 941 941 assert_equal( "Broward labor market's a solid performer (Miami Herald)", text ) 942 942 end 943 943 -
test/changing_encoding.rb
1 1 #!/usr/bin/ruby -Ku 2 # -*- coding: utf-8 -*- 2 3 3 4 require 'kconv' 4 5 require 'iconv' -
test/contrib_test.rb
90 90 assert_equal "myprog-config", doc.root.name 91 91 count = 0 92 92 REXML::XPath.each(doc, "x:myprog-config/x:main/x:parameter", 93 {"x" ,"http://someurl/program/version"}) { |element|93 {"x"=>"http://someurl/program/version"}) { |element| 94 94 assert_equal "name", element.attributes["name"] 95 95 count += 1; 96 96 } … … 227 227 def test_umlaut 228 228 koln_iso = 'Köln' 229 229 koln_utf = 'Köln' 230 if koln_utf.respond_to? :force_encoding 231 koln_utf.force_encoding(Encoding::UTF_8) 232 end 230 233 source_iso = "<?xml version='1.0' encoding='ISO-8859-1'?><test>#{koln_iso}</test>" 231 234 source_utf = "<?xml version='1.0' encoding='UTF-8'?><test>#{koln_utf}</test>" 232 235 doc = REXML::Document.new(source_iso) … … 255 258 </intranet> 256 259 EOF 257 260 tn = XPath.first(doc, "//nebenspalte/text()[2]") 258 assert_equal("Nützliches von Flashern für Flasher.".unpack('C*').pack('U*'), tn.to_s.strip) 261 expected_iso = "Nützliches von Flashern für Flasher." 262 expected_utf = expected_iso.unpack('C*').pack('U*') 263 if expected_utf.respond_to? :encode 264 expected_iso.force_encoding("iso-8859-1") 265 expected_utf.force_encoding(Encoding::UTF_8) 266 end 267 assert_equal(expected_utf, tn.to_s.strip) 259 268 f = REXML::Formatters::Default.new 260 269 f.write( tn, Output.new(o = "", "ISO-8859-1") ) 261 assert_equal( "Nützliches von Flashern für Flasher.", o.strip)270 assert_equal(expected_iso, o.strip) 262 271 263 272 doc = Document.new File.new('test/xmlfile-bug.xml') 264 273 tn = XPath.first(doc, "//nebenspalte/text()[2]") 265 assert_equal( "Nützliches von Flashern für Flasher.".unpack('C*').pack('U*'), tn.to_s.strip)274 assert_equal(expected_utf, tn.to_s.strip) 266 275 f.write( tn, Output.new(o = "", "ISO-8859-1") ) 267 assert_equal( "Nützliches von Flashern für Flasher.", o.strip)276 assert_equal(expected_iso, o.strip) 268 277 end 269 278 270 279 def test_element_cloning_namespace_Chris -
test/jaxen.rb
65 65 got = XPath.match( ctx, valueOfElement.attributes["select"], namespaces, variables )[0] 66 66 assert_true( (got.nil? && expected.nil?) || !got.nil? ) 67 67 case got.class 68 when Element : assert_equal( got.class, Element ) 68 when Element 69 assert_equal( got.class, Element ) 69 70 when Attribute, Text, Comment, TrueClass, FalseClass 70 71 assert_equal( expected, got.to_s ) 71 72 when Instruction -
test/entity.rb
141 141 assert_equal("&", REXML::Text.new("&", false, nil, true).to_s) 142 142 #assert_equal("&", REXML::Text.new("&", false, false).to_s) 143 143 end 144 145 def test_single_pass_unnormalization 146 assert_equal '&&', REXML::Text::unnormalize('&amp;&') 147 end 144 148 end -
test/preceding-sibling.rb
25 25 def test_Dd_preceding_sibling_children 26 26 arr = [] 27 27 XPath.each(@@docDd, "//b[@x='ab02A']/preceding-sibling::b/child::*") do |cell| 28 arr << cell.texts. to_s28 arr << cell.texts.join 29 29 end 30 30 assert_equal( 'Success', arr.join ) 31 31 end -
test/listenertest.rb
83 83 <f a="é" /> 84 84 </g>' 85 85 doc = REXML::Document.new( source ) 86 assert_equal( 'é', doc.elements['/g/f'].attributes['a'] ) 86 a = doc.elements['/g/f'].attribute('a') 87 if a.value.respond_to? :force_encoding 88 a.value.force_encoding('binary') 89 end 90 assert_equal( 'é', a.value) 87 91 doc = REXML::Document.parse_stream( 88 92 File::new("test/stream_accents.xml"), 89 93 AccentListener::new -
test/attributes.rb
187 187 d.root.context[:attribute_quote] = :quote 188 188 assert_equal( %q{<a x="1" y="2"><b z="3"/></a>}, d.to_s ) 189 189 end 190 191 def test_ticket_127 192 doc = Document.new 193 doc.add_element 'a', { 'v' => 'x & y' } 194 assert doc.to_s.index(';') 195 end 190 196 end -
test/encoding.rb
17 17 def test_encoded_in_encoded_out 18 18 doc = Document.new( @encoded ) 19 19 doc.write( out="" ) 20 out.force_encoding('binary') if out.respond_to? :force_encoding 20 21 assert_equal( @encoded, out ) 21 22 end 22 23 … … 28 29 REXML::Formatters::Default.new.write( doc.root, out="" ) 29 30 assert_equal( @not_encoded, out ) 30 31 char = XPath.first( doc, "/a/b/text()" ).to_s 32 char.force_encoding('binary') if char.respond_to? :force_encoding 31 33 assert_equal( "Ä", char ) 32 34 end 33 35 … … 44 46 doc.xml_decl.encoding = "ISO-8859-3" 45 47 assert_equal( doc.encoding, "ISO-8859-3" ) 46 48 doc.write( out="" ) 49 out.force_encoding('binary') if out.respond_to? :force_encoding 47 50 assert_equal( @encoded, out ) 48 51 end 49 52 … … 51 54 def test_in_different_out 52 55 doc = Document.new( @not_encoded ) 53 56 doc.write( Output.new( out="", "ISO-8859-3" ) ) 57 out.force_encoding('binary') if out.respond_to? :force_encoding 54 58 assert_equal( @encoded, out ) 55 59 end 56 60 … … 61 65 <?xml version='1.0' encoding='ISO-8859-1'?> 62 66 <a a="ÿ">ÿ</a> 63 67 EOL 64 assert_equal( doc.elements['a'].attributes['a'], "\303\277" ) 65 assert_equal( doc.elements['a'].text, "\303\277" ) 68 expect = "\303\277" 69 expect.force_encoding('UTF-8') if expect.respond_to? :force_encoding 70 assert_equal( expect, doc.elements['a'].attributes['a'] ) 71 assert_equal( expect, doc.elements['a'].text ) 66 72 end 67 73 68 74 -
test/core_test.rb
656 656 koln_utf8 = "K\xc3\xb6ln" 657 657 source = Source.new( koln_iso_8859_1, 'iso-8859-1' ) 658 658 results = source.scan(/.*/)[0] 659 koln_utf8.force_encoding('UTF-8') if koln_utf8.respond_to?(:force_encoding) 659 660 assert_equal koln_utf8, results 660 661 output << results 662 if koln_iso_8859_1.respond_to?(:force_encoding) 663 koln_iso_8859_1.force_encoding('ISO-8859-1') 664 end 661 665 assert_equal koln_iso_8859_1, out 662 666 end 663 667 -
test/sax.rb
229 229 Thread.stop 230 230 end 231 231 } 232 sleep 1 #to be sure that server is running 232 233 @socket = TCPSocket.new('127.0.0.1',$port) 233 234 234 235 ok = false -
src/rexml/parsers/xpathparser.rb
Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: test/xml/ticket_110_utf16.xml ___________________________________________________________________ Name: svn:mime-type + application/octet-stream
332 332 predicates << expr[1..-2] if expr 333 333 end 334 334 #puts "PREDICATES = #{predicates.inspect}" 335 predicates.each{ | expr|336 #puts "ORING #{ expr}"335 predicates.each{ |pred| 336 #puts "ORING #{pred}" 337 337 preds = [] 338 338 parsed << :predicate 339 339 parsed << preds 340 OrExpr( expr, preds)340 OrExpr(pred, preds) 341 341 } 342 342 #puts "PREDICATES = #{predicates.inspect}" 343 343 path -
src/rexml/parsers/baseparser.rb
242 242 @document_status = :after_doctype 243 243 @source.read if @source.buffer.size<2 244 244 md = @source.match(/\s*/um, true) 245 if @source.encoding == "UTF-8" 246 if @source.buffer.respond_to? :force_encoding 247 @source.buffer.force_encoding(Encoding::UTF_8) 248 end 249 end 245 250 end 246 251 end 247 252 if @document_status == :in_doctype -
src/rexml/parsers/sax2parser.rb
149 149 procs = get_procs( :end_prefix_mapping, event[1] ) 150 150 listeners = get_listeners( :end_prefix_mapping, event[1] ) 151 151 if procs or listeners 152 namespace_mapping.each do | prefix,uri|152 namespace_mapping.each do |ns_prefix, ns_uri| 153 153 # notify observers of namespaces 154 procs.each { |ob| ob.call( prefix ) } if procs155 listeners.each { |ob| ob.end_prefix_mapping( prefix) } if listeners154 procs.each { |ob| ob.call( ns_prefix ) } if procs 155 listeners.each { |ob| ob.end_prefix_mapping(ns_prefix) } if listeners 156 156 end 157 157 end 158 158 when :text 159 159 #normalized = @parser.normalize( event[1] ) 160 160 #handle( :characters, normalized ) 161 161 copy = event[1].clone 162 @entities.each { |key, value| copy = copy.gsub("&#{key};", value) } 162 163 esub = proc { |match| 164 if @entities.has_key?($1) 165 @entities[$1].gsub(Text::REFERENCE, &esub) 166 else 167 match 168 end 169 } 170 171 copy.gsub!( Text::REFERENCE, &esub ) 163 172 copy.gsub!( Text::NUMERICENTITY ) {|m| 164 173 m=$1 165 174 m = "0#{m}" if m[0] == ?x -
src/rexml/parsers/treeparser.rb
30 30 return 31 31 when :start_element 32 32 tag_stack.push(event[1]) 33 el = @build_context = @build_context.add_element( event[1], event[2] ) 33 el = @build_context = @build_context.add_element( event[1] ) 34 event[2].each do |key, value| 35 el.attributes[key]=Attribute.new(key,value,self) 36 end 34 37 when :end_element 35 38 tag_stack.pop 36 39 @build_context = @build_context.parent -
src/rexml/validation/validation.rb
33 33 sattr = [:start_attribute, nil] 34 34 eattr = [:end_attribute] 35 35 text = [:text, nil] 36 k,v = event[2].find { |k ,v|37 sattr[1] = k 36 k,v = event[2].find { |key,value| 37 sattr[1] = key 38 38 #puts "Looking for #{sattr.inspect}" 39 39 m = @current.next( sattr ) 40 40 #puts "Got #{m.inspect}" … … 47 47 @current = m 48 48 else 49 49 #puts "Didn't get end" 50 text[1] = v 50 text[1] = value 51 51 #puts "Looking for #{text.inspect}" 52 52 m = m.next( text ) 53 53 #puts "Got #{m.inspect}" -
src/rexml/element.rb
296 296 raise "First argument must be either an element name, or an Element object" if element.nil? 297 297 el = @elements.add(element) 298 298 attrs.each do |key, value| 299 el.attributes[key]= Attribute.new(key,value,self)299 el.attributes[key]=value 300 300 end if attrs.kind_of? Hash 301 301 el 302 302 end … … 552 552 553 553 def attribute( name, namespace=nil ) 554 554 prefix = nil 555 prefix = namespaces.index(namespace) if namespace 555 if namespaces.respond_to? :key 556 prefix = namespaces.key(namespace) if namespace 557 else 558 prefix = namespaces.index(namespace) if namespace 559 end 556 560 prefix = nil if prefix == 'xmlns' 557 561 attributes.get_attribute( "#{prefix ? prefix + ':' : ''}#{name}" ) 558 562 end … … 704 708 # A private helper method 705 709 def each_with_something( test, max=0, name=nil ) 706 710 num = 0 707 child=nil708 711 @elements.each( name ){ |child| 709 712 yield child if test.call(child) and num += 1 710 713 return if max>0 and num == max … … 754 757 raise "index (#{index}) must be >= 1" if index < 1 755 758 name = literalize(name) if name 756 759 num = 0 757 child = nil758 760 @element.find { |child| 759 761 child.kind_of? Element and 760 762 (name.nil? ? true : child.has_name?( name )) and … … 1217 1219 def get_attribute_ns(namespace, name) 1218 1220 each_attribute() { |attribute| 1219 1221 if name == attribute.name && 1220 namespace == attribute.namespace() 1222 namespace == attribute.namespace() && 1223 ( !namespace.empty? || !attribute.fully_expanded_name.index(':') ) 1221 1224 return attribute 1222 1225 end 1223 1226 } -
src/rexml/source.rb
58 58 @to_utf = true 59 59 else 60 60 @to_utf = false 61 if @buffer.respond_to? :force_encoding 62 @buffer.force_encoding Encoding::UTF_8 63 end 61 64 end 62 65 end 63 66 … … 146 149 str = @source.read( 2 ) 147 150 if encoding 148 151 self.encoding = encoding 149 elsif 0xfe == str[0] && 0xff == str[1]152 elsif str[0,2] == "\xfe\xff" 150 153 @line_break = "\000>" 151 elsif 0xff == str[0] && 0xfe == str[1]154 elsif str[0,2] == "\xff\xfe" 152 155 @line_break = ">\000" 153 elsif 0xef == str[0] && 0xbb == str[1]156 elsif str[0,2] == "\xef\xbb" 154 157 str += @source.read(1) 155 str = '' if ( 0xbf == str[2])158 str = '' if (str[2,1] == "\xBF") 156 159 @line_break = ">" 157 160 else 158 161 @line_break = ">" … … 192 195 str = @source.readline(@line_break) 193 196 str = decode(str) if @to_utf and str 194 197 @buffer << str 198 if not @to_utf and @buffer.respond_to? :force_encoding 199 @buffer.force_encoding Encoding::UTF_8 200 end 195 201 rescue Exception, NameError 196 202 @source = nil 197 203 end -
src/rexml/doctype.rb
117 117 unless @children.empty? 118 118 next_indent = indent + 1 119 119 output << ' [' 120 child = nil # speed121 120 @children.each { |child| 122 121 output << "\n" 123 122 f.write( child, output ) -
src/rexml/functions.rb
256 256 end 257 257 } 258 258 259 string(string).unpack('U*').collect { |c| 260 if map.has_key? c then map[c] else c end 261 }.compact.pack('U*') 259 if ''.respond_to? :chars 260 string(string).chars.collect { |c| 261 if map.has_key? c then map[c] else c end 262 }.compact.join 263 else 264 string(string).unpack('U*').collect { |c| 265 if map.has_key? c then map[c] else c end 266 }.compact.pack('U*') 267 end 262 268 end 263 269 264 270 # UNTESTED -
src/rexml/entity.rb
139 139 if @parent 140 140 matches.each do |entity_reference| 141 141 entity_value = @parent.entity( entity_reference[0] ) 142 rv.gsub!( /%#{entity_reference };/um, entity_value )142 rv.gsub!( /%#{entity_reference.join};/um, entity_value ) 143 143 end 144 144 end 145 145 return rv -
src/rexml/syncenumerator.rb
6 6 # Enumerable objects. 7 7 def initialize(*enums) 8 8 @gens = enums 9 @biggest = @gens[0] 10 @gens.each {|x| @biggest = x if x.size > @biggest.size } 9 @length = @gens.collect {|x| x.size }.max 11 10 end 12 11 13 12 # Returns the number of enumerated Enumerable objects, i.e. the size … … 24 23 25 24 # Enumerates rows of the Enumerable objects. 26 25 def each 27 @ biggest.zip( *@gens ) {|a|28 yield (*a[1..-1])26 @length.times {|i| 27 yield @gens.collect {|x| x[i]} 29 28 } 30 29 self 31 30 end -
src/rexml/text.rb
308 308 309 309 # Unescapes all possible entities 310 310 def Text::unnormalize( string, doctype=nil, filter=nil, illegal=nil ) 311 rv = string.clone 312 rv.gsub!( /\r\n?/, "\n" ) 313 matches = rv.scan( REFERENCE ) 314 return rv if matches.size == 0 315 rv.gsub!( NUMERICENTITY ) {|m| 316 m=$1 317 m = "0#{m}" if m[0] == ?x 318 [Integer(m)].pack('U*') 319 } 320 matches.collect!{|x|x[0]}.compact! 321 if matches.size > 0 322 if doctype 323 matches.each do |entity_reference| 324 unless filter and filter.include?(entity_reference) 325 entity_value = doctype.entity( entity_reference ) 326 re = /&#{entity_reference};/ 327 rv.gsub!( re, entity_value ) if entity_value 328 end 311 string.gsub( /\r\n?/, "\n" ).gsub( REFERENCE ) { |ref| 312 if ref[1] == ?# 313 if ref[2] == ?x 314 [ref[3...-1].to_i(16)].pack('U*') 315 else 316 [ref[2...-1].to_i].pack('U*') 329 317 end 318 elsif ref == '&' 319 '&' 320 elsif filter and filter.include?( ref[1...-1] ) 321 ref 322 elsif doctype 323 doctype.entity( ref[1...-1] ) or ref 330 324 else 331 matches.each do |entity_reference| 332 unless filter and filter.include?(entity_reference) 333 entity_value = DocType::DEFAULT_ENTITIES[ entity_reference ] 334 re = /&#{entity_reference};/ 335 rv.gsub!( re, entity_value.value ) if entity_value 336 end 337 end 325 entity_value = DocType::DEFAULT_ENTITIES[ ref[1...-1] ] 326 entity_value ? entity_value.value : ref 338 327 end 339 rv.gsub!( /&/, '&' ) 340 end 341 rv 328 } 342 329 end 343 330 end 344 331 end -
src/rexml/formatters/pretty.rb
31 31 @level = 0 32 32 @ie_hack = ie_hack 33 33 @width = 80 34 @compact = false 34 35 end 35 36 36 37 protected -
src/rexml/encoding.rb
56 56 57 57 def check_encoding str 58 58 # We have to recognize UTF-16, LSB UTF-16, and UTF-8 59 if str[0 ] == 0xfe && str[1] == 0xff59 if str[0,2] == "\xfe\xff" 60 60 str[0,2] = "" 61 61 return UTF_16 62 elsif str[0 ] == 0xff && str[1] == 0xfe62 elsif str[0,2] == "\xff\xfe" 63 63 str[0,2] = "" 64 64 return UNILE 65 65 end 66 str =~ /^\s*<\?xml\s+version\s*=\s*(['"]).*?\1\s+encoding\s*=\s*(["'])(.*?)\2/ um66 str =~ /^\s*<\?xml\s+version\s*=\s*(['"]).*?\1\s+encoding\s*=\s*(["'])(.*?)\2/m 67 67 return $3.upcase if $3 68 68 return UTF_8 69 69 end -
src/rexml/xpath_parser.rb
222 222 when :child 223 223 new_nodeset = [] 224 224 nt = nil 225 for node in nodeset225 nodeset.each do |node| 226 226 nt = node.node_type 227 227 new_nodeset += node.children if nt == :element or nt == :document 228 228 end … … 266 266 267 267 when :ancestor 268 268 new_nodeset = [] 269 for node in nodeset269 nodeset.each do |node| 270 270 while node.parent 271 271 node = node.parent 272 272 new_nodeset << node unless new_nodeset.include? node … … 277 277 278 278 when :ancestor_or_self 279 279 new_nodeset = [] 280 for node in nodeset280 nodeset.each do |node| 281 281 if node.node_type == :element 282 282 new_nodeset << node 283 283 while ( node.parent ) … … 341 341 when :descendant 342 342 results = [] 343 343 nt = nil 344 for node in nodeset344 nodeset.each do |node| 345 345 nt = node.node_type 346 346 results += expr( path_stack.dclone.unshift( :descendant_or_self ), 347 347 node.children ) if nt == :element or nt == :document … … 376 376 377 377 when :preceding 378 378 new_nodeset = [] 379 for node in nodeset379 nodeset.each do |node| 380 380 new_nodeset += preceding( node ) 381 381 end 382 382 #puts "NEW NODESET => #{new_nodeset.inspect}" … … 385 385 386 386 when :following 387 387 new_nodeset = [] 388 for node in nodeset388 nodeset.each do |node| 389 389 new_nodeset += following( node ) 390 390 end 391 391 nodeset = new_nodeset … … 395 395 #puts "In :namespace" 396 396 new_nodeset = [] 397 397 prefix = path_stack.shift 398 for node in nodeset398 nodeset.each do |node| 399 399 if (node.node_type == :element or node.node_type == :attribute) 400 400 if @namespaces 401 401 namespaces = @namespaces
