lib/nokogumbo/html5/document.rb in nokogumbo-2.0.2 vs lib/nokogumbo/html5/document.rb in nokogumbo-2.0.3
- old
+ new
@@ -10,20 +10,24 @@
end
if string_or_io.respond_to?(:read) && string_or_io.respond_to?(:path)
url ||= string_or_io.path
end
+ unless string_or_io.respond_to?(:read) || string_or_io.respond_to?(:to_str)
+ raise ArgumentError.new("not a string or IO object")
+ end
do_parse(string_or_io, url, encoding, options)
end
def self.read_io(io, url = nil, encoding = nil, **options)
raise ArgumentError.new("io object doesn't respond to :read") unless io.respond_to?(:read)
do_parse(io, url, encoding, options)
end
def self.read_memory(string, url = nil, encoding = nil, **options)
- do_parse(string.to_s, url, encoding, options)
+ raise ArgumentError.new("string object doesn't respond to :to_str") unless string.respond_to?(:to_str)
+ do_parse(string, url, encoding, options)
end
def fragment(tags = nil)
DocumentFragment.new(self, tags, self.root)
end
@@ -35,12 +39,13 @@
end
private
def self.do_parse(string_or_io, url, encoding, options)
string = HTML5.read_and_encode(string_or_io, encoding)
+ max_attributes = options[:max_attributes] || Nokogumbo::DEFAULT_MAX_ATTRIBUTES
max_errors = options[:max_errors] || options[:max_parse_errors] || Nokogumbo::DEFAULT_MAX_ERRORS
max_depth = options[:max_tree_depth] || Nokogumbo::DEFAULT_MAX_TREE_DEPTH
- doc = Nokogumbo.parse(string.to_s, url, max_errors, max_depth)
+ doc = Nokogumbo.parse(string, url, max_attributes, max_errors, max_depth)
doc.encoding = 'UTF-8'
doc
end
end
end