mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
merge r23451.
* lib/rss/parser.rb, test/test_parser_1.0.rb: fix foaf:Image element causes parse error even if ignore_unknown_element mode. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@23464 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6a5794bd7c
commit
0b5294ba03
6 changed files with 49 additions and 11 deletions
|
@ -1,3 +1,8 @@
|
|||
Sat May 16 19:48:29 2009 Kouhei Sutou <kou@cozmixng.org>
|
||||
|
||||
* lib/rss/parser.rb, test/test_parser_1.0.rb: fix foaf:Image
|
||||
element causes parse error even if ignore_unknown_element mode.
|
||||
|
||||
Sat May 16 19:46:30 2009 Kouhei Sutou <kou@cozmixng.org>
|
||||
|
||||
* lib/rss/maker.rb, lib/rss/maker/0.9.rb,
|
||||
|
|
|
@ -411,7 +411,7 @@ module RSS
|
|||
module ListenerMixin
|
||||
private
|
||||
def initial_start_rss(tag_name, prefix, attrs, ns)
|
||||
check_ns(tag_name, prefix, ns, "")
|
||||
check_ns(tag_name, prefix, ns, "", false)
|
||||
|
||||
@rss = Rss.new(attrs['version'], @version, @encoding, @standalone)
|
||||
@rss.do_validate = @do_validate
|
||||
|
|
|
@ -436,7 +436,7 @@ module RSS
|
|||
module ListenerMixin
|
||||
private
|
||||
def initial_start_RDF(tag_name, prefix, attrs, ns)
|
||||
check_ns(tag_name, prefix, ns, RDF::URI)
|
||||
check_ns(tag_name, prefix, ns, RDF::URI, false)
|
||||
|
||||
@rss = RDF.new(@version, @encoding, @standalone)
|
||||
@rss.do_validate = @do_validate
|
||||
|
|
|
@ -716,7 +716,7 @@ module RSS
|
|||
module ListenerMixin
|
||||
private
|
||||
def initial_start_feed(tag_name, prefix, attrs, ns)
|
||||
check_ns(tag_name, prefix, ns, Atom::URI)
|
||||
check_ns(tag_name, prefix, ns, Atom::URI, false)
|
||||
|
||||
@rss = Atom::Feed.new(@version, @encoding, @standalone)
|
||||
@rss.do_validate = @do_validate
|
||||
|
@ -731,7 +731,7 @@ module RSS
|
|||
end
|
||||
|
||||
def initial_start_entry(tag_name, prefix, attrs, ns)
|
||||
check_ns(tag_name, prefix, ns, Atom::URI)
|
||||
check_ns(tag_name, prefix, ns, Atom::URI, false)
|
||||
|
||||
@rss = Atom::Entry.new(@version, @encoding, @standalone)
|
||||
@rss.do_validate = @do_validate
|
||||
|
|
|
@ -392,7 +392,7 @@ module RSS
|
|||
start_have_something_element(local, prefix, attrs, ns, next_class)
|
||||
else
|
||||
if !@do_validate or @ignore_unknown_element
|
||||
@proc_stack.push(nil)
|
||||
@proc_stack.push(setup_next_element_in_unknown_element)
|
||||
else
|
||||
parent = "ROOT ELEMENT???"
|
||||
if current_class.tag_name
|
||||
|
@ -423,13 +423,22 @@ module RSS
|
|||
[$1 || '', $2]
|
||||
end
|
||||
|
||||
def check_ns(tag_name, prefix, ns, require_uri)
|
||||
unless _ns(ns, prefix) == require_uri
|
||||
if @do_validate
|
||||
def check_ns(tag_name, prefix, ns, require_uri, ignore_unknown_element=nil)
|
||||
if _ns(ns, prefix) == require_uri
|
||||
true
|
||||
else
|
||||
if ignore_unknown_element.nil?
|
||||
ignore_unknown_element = @ignore_unknown_element
|
||||
end
|
||||
|
||||
if ignore_unknown_element
|
||||
false
|
||||
elsif @do_validate
|
||||
raise NSError.new(tag_name, prefix, require_uri)
|
||||
else
|
||||
# Force bind required URI with prefix
|
||||
@ns_stack.last[prefix] = require_uri
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -456,9 +465,12 @@ module RSS
|
|||
end
|
||||
|
||||
def start_have_something_element(tag_name, prefix, attrs, ns, klass)
|
||||
check_ns(tag_name, prefix, ns, klass.required_uri)
|
||||
if check_ns(tag_name, prefix, ns, klass.required_uri)
|
||||
attributes = collect_attributes(tag_name, prefix, attrs, ns, klass)
|
||||
@proc_stack.push(setup_next_element(tag_name, klass, attributes))
|
||||
else
|
||||
@proc_stack.push(setup_next_element_in_unknown_element)
|
||||
end
|
||||
end
|
||||
|
||||
def collect_attributes(tag_name, prefix, attrs, ns, klass)
|
||||
|
@ -525,6 +537,11 @@ module RSS
|
|||
@last_element = previous
|
||||
end
|
||||
end
|
||||
|
||||
def setup_next_element_in_unknown_element
|
||||
current_element, @last_element = @last_element, nil
|
||||
Proc.new {@last_element = current_element}
|
||||
end
|
||||
end
|
||||
|
||||
unless const_defined? :AVAILABLE_PARSER_LIBRARIES
|
||||
|
|
|
@ -507,6 +507,22 @@ EOR
|
|||
#{make_image}
|
||||
EOR
|
||||
end
|
||||
|
||||
def test_unknown_case_insensitive_duplicated_element
|
||||
xmlns = {
|
||||
"foaf" => "http://xmlns.com/foaf/0.1/",
|
||||
"dc" => "http://purl.org/dc/elements/1.1/",
|
||||
}
|
||||
assert_parse(make_RDF(<<-EOR, xmlns), :nothing_raised)
|
||||
#{make_channel}
|
||||
#{make_item}
|
||||
#{make_image}
|
||||
<foaf:Image rdf:about="http://example.com/myself.png">
|
||||
<dc:title>Myself</dc:title>
|
||||
<dc:link>http://example.com/</dc:link>
|
||||
</foaf:Image>
|
||||
EOR
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue