1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* Non-String attributes are now converted to Strings; this means code such as

elem.attributes["a"] = 1
  will not cause an error when dumping the XML.  It also means that:
  elem.attributes["a"]    # => "1", not 1
* Transitive indenting has been cleaned up.
* Fixed a potential bug in parsing non-ASCII encoded streams
* Fixed a bug where trying to fill in ParseException data was causing an
  IO error (stream closed)
* Changes to Text mean that Element (and Text) can be used outside of a
  Document context.
* In some rare cases, the base parser wasn't reading enough bytes from the
  stream for the parsing algorithm to work properly.  This has been fixed
  (this was Ruby bug #48426)


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6209 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ser 2004-04-23 15:44:30 +00:00
parent 7792d9026a
commit d15f41b0eb
7 changed files with 49 additions and 27 deletions

View file

@ -36,7 +36,7 @@ module REXML
elsif first.kind_of? String elsif first.kind_of? String
@element = parent if parent.kind_of? Element @element = parent if parent.kind_of? Element
self.name = first self.name = first
@value = second @value = second.to_s
else else
raise "illegal argument #{first.class.name} to Attribute constructor" raise "illegal argument #{first.class.name} to Attribute constructor"
end end

View file

@ -54,6 +54,10 @@ module REXML
indent( output, indent ) indent( output, indent )
output << START output << START
output << @string output << @string
if indent>-1
output << "\n"
indent( output, indent )
end
output << STOP output << STOP
end end

View file

@ -635,7 +635,12 @@ module REXML
end unless @attributes.empty? end unless @attributes.empty?
if @children.empty? if @children.empty?
writer << " " if ie_hack if transitive and indent>-1
writer << "\n"
indent( writer, indent )
elsif ie_hack
writer << " "
end
writer << "/" writer << "/"
else else
if transitive and indent>-1 and !@children[0].kind_of? Text if transitive and indent>-1 and !@children[0].kind_of? Text
@ -646,7 +651,7 @@ module REXML
write_children( writer, indent, transitive, ie_hack ) write_children( writer, indent, transitive, ie_hack )
writer << "</#{expanded_name}" writer << "</#{expanded_name}"
end end
if transitive and indent>-1 if transitive and indent>-1 and !@children.empty?
writer << "\n" writer << "\n"
indent -= 1 if next_sibling.nil? indent -= 1 if next_sibling.nil?
indent(writer, indent) indent(writer, indent)

View file

@ -166,7 +166,7 @@ module REXML
return [ :end_element, x ] return [ :end_element, x ]
end end
return @stack.shift if @stack.size > 0 return @stack.shift if @stack.size > 0
@source.read if @source.buffer.size==0 @source.read if @source.buffer.size<2
if @document_status == nil if @document_status == nil
@source.consume( /^\s*/um ) @source.consume( /^\s*/um )
word = @source.match( /(<[^>]*)>/um ) word = @source.match( /(<[^>]*)>/um )
@ -199,7 +199,7 @@ module REXML
args = [ :start_doctype, name, pub_sys, long_name, uri ] args = [ :start_doctype, name, pub_sys, long_name, uri ]
if close == ">" if close == ">"
@document_status = :after_doctype @document_status = :after_doctype
@source.read if @source.buffer.size==0 @source.read if @source.buffer.size<2
md = @source.match(/^\s*/um, true) md = @source.match(/^\s*/um, true)
@stack << [ :end_doctype ] @stack << [ :end_doctype ]
else else
@ -208,7 +208,7 @@ module REXML
return args return args
else else
@document_status = :after_doctype @document_status = :after_doctype
@source.read if @source.buffer.size==0 @source.read if @source.buffer.size<2
md = @source.match(/\s*/um, true) md = @source.match(/\s*/um, true)
end end
end end

View file

@ -10,13 +10,17 @@
# #
# Main page:: http://www.germane-software.com/software/rexml # Main page:: http://www.germane-software.com/software/rexml
# Author:: Sean Russell <serATgermaneHYPHENsoftwareDOTcom> # Author:: Sean Russell <serATgermaneHYPHENsoftwareDOTcom>
# Version:: 3.0.3 # Version:: 3.0.4
# Date:: +2004/098 # Date:: +2004/114
# #
# This API documentation can be downloaded from the REXML home page, or can # This API documentation can be downloaded from the REXML home page, or can
# be accessed online[http://www.germane-software.com/software/rexml_doc] # be accessed online[http://www.germane-software.com/software/rexml_doc]
#
# A tutorial is available in the REXML distribution in docs/tutorial.html,
# or can be accessed
# online[http://www.germane-software.com/software/rexml/docs/tutorial.html]
module REXML module REXML
Copyright = "Copyright © 2001, 2002, 2003, 2004 Sean Russell <ser@germane-software.com>" Copyright = "Copyright © 2001, 2002, 2003, 2004 Sean Russell <ser@germane-software.com>"
Date = "+2004/098" Date = "+2004/114"
Version = "3.0.3" Version = "3.0.4"
end end

View file

@ -150,7 +150,7 @@ module REXML
def read def read
begin begin
str = @source.readline('>') str = @source.readline(@line_break)
str = decode(str) if @to_utf and str str = decode(str) if @to_utf and str
@buffer << str @buffer << str
rescue Exception, NameError rescue Exception, NameError
@ -167,7 +167,7 @@ module REXML
@buffer = $' if cons and rv @buffer = $' if cons and rv
while !rv and @source while !rv and @source
begin begin
str = @source.readline('>') str = @source.readline(@line_break)
str = decode(str) if @to_utf and str str = decode(str) if @to_utf and str
@buffer << str @buffer << str
rv = pattern.match(@buffer) rv = pattern.match(@buffer)
@ -186,17 +186,22 @@ module REXML
# @return the current line in the source # @return the current line in the source
def current_line def current_line
pos = @er_source.pos # The byte position in the source begin
lineno = @er_source.lineno # The XML < position in the source pos = @er_source.pos # The byte position in the source
@er_source.rewind lineno = @er_source.lineno # The XML < position in the source
line = 0 # The \r\n position in the source @er_source.rewind
begin line = 0 # The \r\n position in the source
while @er_source.pos < pos begin
@er_source.readline while @er_source.pos < pos
line += 1 @er_source.readline
end line += 1
rescue end
end rescue
end
rescue IOError
pos = -1
line = -1
end
[pos, lineno, line] [pos, lineno, line]
end end
end end

View file

@ -1,4 +1,8 @@
require 'rexml/entity' require 'rexml/entity'
require 'rexml/doctype'
require 'rexml/child'
require 'rexml/doctype'
require 'rexml/parseexception'
module REXML module REXML
# Represents text nodes in an XML document # Represents text nodes in an XML document
@ -271,16 +275,16 @@ module REXML
copy = input.clone copy = input.clone
# Doing it like this rather than in a loop improves the speed # Doing it like this rather than in a loop improves the speed
if doctype if doctype
copy.gsub!( EREFERENCE, '&amp;' ) copy = copy.gsub( EREFERENCE, '&amp;' )
doctype.entities.each_value do |entity| doctype.entities.each_value do |entity|
copy.gsub!( entity.value, copy = copy.gsub( entity.value,
"&#{entity.name};" ) if entity.value and "&#{entity.name};" ) if entity.value and
not( entity_filter and entity_filter.include?(entity) ) not( entity_filter and entity_filter.include?(entity) )
end end
else else
copy.gsub!( EREFERENCE, '&amp;' ) copy = copy.gsub( EREFERENCE, '&amp;' )
DocType::DEFAULT_ENTITIES.each_value do |entity| DocType::DEFAULT_ENTITIES.each_value do |entity|
copy.gsub!(entity.value, "&#{entity.name};" ) copy = copy.gsub(entity.value, "&#{entity.name};" )
end end
end end
copy copy