aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rexml/parsers
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-01 05:43:50 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-01 05:43:50 +0000
commit1448668244c81cfc720bcdfa93af352a17cc230f (patch)
tree550af4707b22d099f4d8393e29ef6da424aca813 /lib/rexml/parsers
parent96e7713754c477fe98806b905301356371accb68 (diff)
downloadruby-1448668244c81cfc720bcdfa93af352a17cc230f.tar.gz
* lib/rexml: 1.9 patch from Sam Ruby mentioned in his blog:
<http://intertwingly.net/blog/2007/12/31/Porting-REXML-to-Ruby-1-9> [ruby-core:14639] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14826 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rexml/parsers')
-rw-r--r--lib/rexml/parsers/baseparser.rb5
-rw-r--r--lib/rexml/parsers/sax2parser.rb17
-rw-r--r--lib/rexml/parsers/treeparser.rb5
-rw-r--r--lib/rexml/parsers/xpathparser.rb6
4 files changed, 25 insertions, 8 deletions
diff --git a/lib/rexml/parsers/baseparser.rb b/lib/rexml/parsers/baseparser.rb
index fc2354a67f..854e707fae 100644
--- a/lib/rexml/parsers/baseparser.rb
+++ b/lib/rexml/parsers/baseparser.rb
@@ -242,6 +242,11 @@ module REXML
@document_status = :after_doctype
@source.read if @source.buffer.size<2
md = @source.match(/\s*/um, true)
+ if @source.encoding == "UTF-8"
+ if @source.buffer.respond_to? :force_encoding
+ @source.buffer.force_encoding(Encoding::UTF_8)
+ end
+ end
end
end
if @document_status == :in_doctype
diff --git a/lib/rexml/parsers/sax2parser.rb b/lib/rexml/parsers/sax2parser.rb
index e402eb7747..cafc39375d 100644
--- a/lib/rexml/parsers/sax2parser.rb
+++ b/lib/rexml/parsers/sax2parser.rb
@@ -149,17 +149,26 @@ module REXML
procs = get_procs( :end_prefix_mapping, event[1] )
listeners = get_listeners( :end_prefix_mapping, event[1] )
if procs or listeners
- namespace_mapping.each do |prefix, uri|
+ namespace_mapping.each do |ns_prefix, ns_uri|
# notify observers of namespaces
- procs.each { |ob| ob.call( prefix ) } if procs
- listeners.each { |ob| ob.end_prefix_mapping(prefix) } if listeners
+ procs.each { |ob| ob.call( ns_prefix ) } if procs
+ listeners.each { |ob| ob.end_prefix_mapping(ns_prefix) } if listeners
end
end
when :text
#normalized = @parser.normalize( event[1] )
#handle( :characters, normalized )
copy = event[1].clone
- @entities.each { |key, value| copy = copy.gsub("&#{key};", value) }
+
+ esub = proc { |match|
+ if @entities.has_key?($1)
+ @entities[$1].gsub(Text::REFERENCE, &esub)
+ else
+ match
+ end
+ }
+
+ copy.gsub!( Text::REFERENCE, &esub )
copy.gsub!( Text::NUMERICENTITY ) {|m|
m=$1
m = "0#{m}" if m[0] == ?x
diff --git a/lib/rexml/parsers/treeparser.rb b/lib/rexml/parsers/treeparser.rb
index 5c3e142ea7..30327d0dfd 100644
--- a/lib/rexml/parsers/treeparser.rb
+++ b/lib/rexml/parsers/treeparser.rb
@@ -30,7 +30,10 @@ module REXML
return
when :start_element
tag_stack.push(event[1])
- el = @build_context = @build_context.add_element( event[1], event[2] )
+ el = @build_context = @build_context.add_element( event[1] )
+ event[2].each do |key, value|
+ el.attributes[key]=Attribute.new(key,value,self)
+ end
when :end_element
tag_stack.pop
@build_context = @build_context.parent
diff --git a/lib/rexml/parsers/xpathparser.rb b/lib/rexml/parsers/xpathparser.rb
index de2530e347..152198856d 100644
--- a/lib/rexml/parsers/xpathparser.rb
+++ b/lib/rexml/parsers/xpathparser.rb
@@ -332,12 +332,12 @@ module REXML
predicates << expr[1..-2] if expr
end
#puts "PREDICATES = #{predicates.inspect}"
- predicates.each{ |expr|
- #puts "ORING #{expr}"
+ predicates.each{ |pred|
+ #puts "ORING #{pred}"
preds = []
parsed << :predicate
parsed << preds
- OrExpr(expr, preds)
+ OrExpr(pred, preds)
}
#puts "PREDICATES = #{predicates.inspect}"
path