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:
parent
7792d9026a
commit
d15f41b0eb
7 changed files with 49 additions and 27 deletions
|
@ -36,7 +36,7 @@ module REXML
|
|||
elsif first.kind_of? String
|
||||
@element = parent if parent.kind_of? Element
|
||||
self.name = first
|
||||
@value = second
|
||||
@value = second.to_s
|
||||
else
|
||||
raise "illegal argument #{first.class.name} to Attribute constructor"
|
||||
end
|
||||
|
|
|
@ -54,6 +54,10 @@ module REXML
|
|||
indent( output, indent )
|
||||
output << START
|
||||
output << @string
|
||||
if indent>-1
|
||||
output << "\n"
|
||||
indent( output, indent )
|
||||
end
|
||||
output << STOP
|
||||
end
|
||||
|
||||
|
|
|
@ -635,7 +635,12 @@ module REXML
|
|||
end unless @attributes.empty?
|
||||
|
||||
if @children.empty?
|
||||
writer << " " if ie_hack
|
||||
if transitive and indent>-1
|
||||
writer << "\n"
|
||||
indent( writer, indent )
|
||||
elsif ie_hack
|
||||
writer << " "
|
||||
end
|
||||
writer << "/"
|
||||
else
|
||||
if transitive and indent>-1 and !@children[0].kind_of? Text
|
||||
|
@ -646,7 +651,7 @@ module REXML
|
|||
write_children( writer, indent, transitive, ie_hack )
|
||||
writer << "</#{expanded_name}"
|
||||
end
|
||||
if transitive and indent>-1
|
||||
if transitive and indent>-1 and !@children.empty?
|
||||
writer << "\n"
|
||||
indent -= 1 if next_sibling.nil?
|
||||
indent(writer, indent)
|
||||
|
|
|
@ -166,7 +166,7 @@ module REXML
|
|||
return [ :end_element, x ]
|
||||
end
|
||||
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
|
||||
@source.consume( /^\s*/um )
|
||||
word = @source.match( /(<[^>]*)>/um )
|
||||
|
@ -199,7 +199,7 @@ module REXML
|
|||
args = [ :start_doctype, name, pub_sys, long_name, uri ]
|
||||
if close == ">"
|
||||
@document_status = :after_doctype
|
||||
@source.read if @source.buffer.size==0
|
||||
@source.read if @source.buffer.size<2
|
||||
md = @source.match(/^\s*/um, true)
|
||||
@stack << [ :end_doctype ]
|
||||
else
|
||||
|
@ -208,7 +208,7 @@ module REXML
|
|||
return args
|
||||
else
|
||||
@document_status = :after_doctype
|
||||
@source.read if @source.buffer.size==0
|
||||
@source.read if @source.buffer.size<2
|
||||
md = @source.match(/\s*/um, true)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,13 +10,17 @@
|
|||
#
|
||||
# Main page:: http://www.germane-software.com/software/rexml
|
||||
# Author:: Sean Russell <serATgermaneHYPHENsoftwareDOTcom>
|
||||
# Version:: 3.0.3
|
||||
# Date:: +2004/098
|
||||
# Version:: 3.0.4
|
||||
# Date:: +2004/114
|
||||
#
|
||||
# This API documentation can be downloaded from the REXML home page, or can
|
||||
# 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
|
||||
Copyright = "Copyright © 2001, 2002, 2003, 2004 Sean Russell <ser@germane-software.com>"
|
||||
Date = "+2004/098"
|
||||
Version = "3.0.3"
|
||||
Date = "+2004/114"
|
||||
Version = "3.0.4"
|
||||
end
|
||||
|
|
|
@ -150,7 +150,7 @@ module REXML
|
|||
|
||||
def read
|
||||
begin
|
||||
str = @source.readline('>')
|
||||
str = @source.readline(@line_break)
|
||||
str = decode(str) if @to_utf and str
|
||||
@buffer << str
|
||||
rescue Exception, NameError
|
||||
|
@ -167,7 +167,7 @@ module REXML
|
|||
@buffer = $' if cons and rv
|
||||
while !rv and @source
|
||||
begin
|
||||
str = @source.readline('>')
|
||||
str = @source.readline(@line_break)
|
||||
str = decode(str) if @to_utf and str
|
||||
@buffer << str
|
||||
rv = pattern.match(@buffer)
|
||||
|
@ -186,17 +186,22 @@ module REXML
|
|||
|
||||
# @return the current line in the source
|
||||
def current_line
|
||||
pos = @er_source.pos # The byte position in the source
|
||||
lineno = @er_source.lineno # The XML < position in the source
|
||||
@er_source.rewind
|
||||
line = 0 # The \r\n position in the source
|
||||
begin
|
||||
while @er_source.pos < pos
|
||||
@er_source.readline
|
||||
line += 1
|
||||
end
|
||||
rescue
|
||||
end
|
||||
begin
|
||||
pos = @er_source.pos # The byte position in the source
|
||||
lineno = @er_source.lineno # The XML < position in the source
|
||||
@er_source.rewind
|
||||
line = 0 # The \r\n position in the source
|
||||
begin
|
||||
while @er_source.pos < pos
|
||||
@er_source.readline
|
||||
line += 1
|
||||
end
|
||||
rescue
|
||||
end
|
||||
rescue IOError
|
||||
pos = -1
|
||||
line = -1
|
||||
end
|
||||
[pos, lineno, line]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
require 'rexml/entity'
|
||||
require 'rexml/doctype'
|
||||
require 'rexml/child'
|
||||
require 'rexml/doctype'
|
||||
require 'rexml/parseexception'
|
||||
|
||||
module REXML
|
||||
# Represents text nodes in an XML document
|
||||
|
@ -271,16 +275,16 @@ module REXML
|
|||
copy = input.clone
|
||||
# Doing it like this rather than in a loop improves the speed
|
||||
if doctype
|
||||
copy.gsub!( EREFERENCE, '&' )
|
||||
copy = copy.gsub( EREFERENCE, '&' )
|
||||
doctype.entities.each_value do |entity|
|
||||
copy.gsub!( entity.value,
|
||||
copy = copy.gsub( entity.value,
|
||||
"&#{entity.name};" ) if entity.value and
|
||||
not( entity_filter and entity_filter.include?(entity) )
|
||||
end
|
||||
else
|
||||
copy.gsub!( EREFERENCE, '&' )
|
||||
copy = copy.gsub( EREFERENCE, '&' )
|
||||
DocType::DEFAULT_ENTITIES.each_value do |entity|
|
||||
copy.gsub!(entity.value, "&#{entity.name};" )
|
||||
copy = copy.gsub(entity.value, "&#{entity.name};" )
|
||||
end
|
||||
end
|
||||
copy
|
||||
|
|
Loading…
Reference in a new issue