summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/rexml/attribute.rb2
-rw-r--r--lib/rexml/comment.rb4
-rw-r--r--lib/rexml/element.rb9
-rw-r--r--lib/rexml/parsers/baseparser.rb6
-rw-r--r--lib/rexml/rexml.rb12
-rw-r--r--lib/rexml/source.rb31
-rw-r--r--lib/rexml/text.rb12
7 files changed, 49 insertions, 27 deletions
diff --git a/lib/rexml/attribute.rb b/lib/rexml/attribute.rb
index df07ce7a18..90d7e66122 100644
--- a/lib/rexml/attribute.rb
+++ b/lib/rexml/attribute.rb
@@ -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
diff --git a/lib/rexml/comment.rb b/lib/rexml/comment.rb
index 7c3e79fe2a..334017cbfc 100644
--- a/lib/rexml/comment.rb
+++ b/lib/rexml/comment.rb
@@ -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
diff --git a/lib/rexml/element.rb b/lib/rexml/element.rb
index aba57d708c..40cac168b9 100644
--- a/lib/rexml/element.rb
+++ b/lib/rexml/element.rb
@@ -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)
diff --git a/lib/rexml/parsers/baseparser.rb b/lib/rexml/parsers/baseparser.rb
index 025d43db54..92033a9c2b 100644
--- a/lib/rexml/parsers/baseparser.rb
+++ b/lib/rexml/parsers/baseparser.rb
@@ -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
diff --git a/lib/rexml/rexml.rb b/lib/rexml/rexml.rb
index 18bdbc337d..dcae04e954 100644
--- a/lib/rexml/rexml.rb
+++ b/lib/rexml/rexml.rb
@@ -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/115
#
# 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/115"
+ Version = "3.0.4"
end
diff --git a/lib/rexml/source.rb b/lib/rexml/source.rb
index a524e483ef..ce10d03a6c 100644
--- a/lib/rexml/source.rb
+++ b/lib/rexml/source.rb
@@ -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
diff --git a/lib/rexml/text.rb b/lib/rexml/text.rb
index 2e54f9fa11..1d2d2dd711 100644
--- a/lib/rexml/text.rb
+++ b/lib/rexml/text.rb
@@ -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, '&amp;' )
+ copy = copy.gsub( EREFERENCE, '&amp;' )
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, '&amp;' )
+ copy = copy.gsub( EREFERENCE, '&amp;' )
DocType::DEFAULT_ENTITIES.each_value do |entity|
- copy.gsub!(entity.value, "&#{entity.name};" )
+ copy = copy.gsub(entity.value, "&#{entity.name};" )
end
end
copy