aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/dependencies.rb15
-rw-r--r--activesupport/lib/active_support/xml_mini/libxml.rb14
-rw-r--r--activesupport/lib/active_support/xml_mini/nokogiri.rb10
-rw-r--r--activesupport/lib/active_support/xml_mini/rexml.rb18
4 files changed, 36 insertions, 21 deletions
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index 855b720ef1..7f6f012721 100644
--- a/activesupport/lib/active_support/dependencies.rb
+++ b/activesupport/lib/active_support/dependencies.rb
@@ -143,8 +143,8 @@ module ActiveSupport #:nodoc:
Dependencies.require_or_load(file_name)
end
- def require_dependency(file_name)
- Dependencies.depend_on(file_name)
+ def require_dependency(file_name, message = "No such file to load -- %s")
+ Dependencies.depend_on(file_name, false, message)
end
def require_association(file_name)
@@ -230,11 +230,16 @@ module ActiveSupport #:nodoc:
mechanism == :load
end
- def depend_on(file_name, swallow_load_errors = false)
+ def depend_on(file_name, swallow_load_errors = false, message = "No such file to load -- %s.rb")
path = search_for_file(file_name)
require_or_load(path || file_name)
- rescue LoadError
- raise unless swallow_load_errors
+ rescue LoadError => load_error
+ unless swallow_load_errors
+ if file_name = load_error.message[/ -- (.*?)(\.rb)?$/, 1]
+ raise MissingSourceFile.new(message % file_name, load_error.path).copy_blame!(load_error)
+ end
+ raise
+ end
end
def associate_with(file_name)
diff --git a/activesupport/lib/active_support/xml_mini/libxml.rb b/activesupport/lib/active_support/xml_mini/libxml.rb
index d4c4dc7be5..2ae22c35fb 100644
--- a/activesupport/lib/active_support/xml_mini/libxml.rb
+++ b/activesupport/lib/active_support/xml_mini/libxml.rb
@@ -9,16 +9,18 @@ module ActiveSupport
# data::
# XML Document string or IO to parse
def parse(data)
- if data.respond_to?(:read)
- data = data.read
+ if !data.respond_to?(:read)
+ data = StringIO.new(data || '')
end
-
+
LibXML::XML.default_keep_blanks = false
-
- if data.blank?
+
+ char = data.getc
+ if char.nil?
{}
else
- LibXML::XML::Parser.string(data.strip).parse.to_hash
+ data.ungetc(char)
+ LibXML::XML::Parser.io(data).parse.to_hash
end
end
diff --git a/activesupport/lib/active_support/xml_mini/nokogiri.rb b/activesupport/lib/active_support/xml_mini/nokogiri.rb
index 7337c143c9..622523a1b9 100644
--- a/activesupport/lib/active_support/xml_mini/nokogiri.rb
+++ b/activesupport/lib/active_support/xml_mini/nokogiri.rb
@@ -9,13 +9,15 @@ module ActiveSupport
# data::
# XML Document string or IO to parse
def parse(data)
- if data.respond_to?(:read)
- data = data.read
+ if !data.respond_to?(:read)
+ data = StringIO.new(data || '')
end
-
- if data.blank?
+
+ char = data.getc
+ if char.nil?
{}
else
+ data.ungetc(char)
doc = Nokogiri::XML(data)
raise doc.errors.first if doc.errors.length > 0
doc.to_hash
diff --git a/activesupport/lib/active_support/xml_mini/rexml.rb b/activesupport/lib/active_support/xml_mini/rexml.rb
index 1184d2d6c9..aa2461535b 100644
--- a/activesupport/lib/active_support/xml_mini/rexml.rb
+++ b/activesupport/lib/active_support/xml_mini/rexml.rb
@@ -15,13 +15,19 @@ module ActiveSupport
# data::
# XML Document string or IO to parse
def parse(data)
- if data.respond_to?(:read)
- data = data.read
+ if !data.respond_to?(:read)
+ data = StringIO.new(data || '')
+ end
+
+ char = data.getc
+ if char.nil?
+ {}
+ else
+ data.ungetc(char)
+ require 'rexml/document' unless defined?(REXML::Document)
+ doc = REXML::Document.new(data)
+ merge_element!({}, doc.root)
end
-
- require 'rexml/document' unless defined?(REXML::Document)
- doc = REXML::Document.new(data)
- merge_element!({}, doc.root)
end
private