* 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/trunk@23451 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a687b15ff8
commit
86f2dc7425
@ -1,3 +1,8 @@
|
|||||||
|
Sat May 16 18:26:42 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 18:14:19 2009 Kouhei Sutou <kou@cozmixng.org>
|
Sat May 16 18:14:19 2009 Kouhei Sutou <kou@cozmixng.org>
|
||||||
|
|
||||||
* lib/rss/maker.rb, lib/rss/maker/0.9.rb,
|
* lib/rss/maker.rb, lib/rss/maker/0.9.rb,
|
||||||
|
@ -411,7 +411,7 @@ module RSS
|
|||||||
module ListenerMixin
|
module ListenerMixin
|
||||||
private
|
private
|
||||||
def initial_start_rss(tag_name, prefix, attrs, ns)
|
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 = Rss.new(attrs['version'], @version, @encoding, @standalone)
|
||||||
@rss.do_validate = @do_validate
|
@rss.do_validate = @do_validate
|
||||||
|
@ -436,7 +436,7 @@ module RSS
|
|||||||
module ListenerMixin
|
module ListenerMixin
|
||||||
private
|
private
|
||||||
def initial_start_RDF(tag_name, prefix, attrs, ns)
|
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 = RDF.new(@version, @encoding, @standalone)
|
||||||
@rss.do_validate = @do_validate
|
@rss.do_validate = @do_validate
|
||||||
|
@ -716,7 +716,7 @@ module RSS
|
|||||||
module ListenerMixin
|
module ListenerMixin
|
||||||
private
|
private
|
||||||
def initial_start_feed(tag_name, prefix, attrs, ns)
|
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 = Atom::Feed.new(@version, @encoding, @standalone)
|
||||||
@rss.do_validate = @do_validate
|
@rss.do_validate = @do_validate
|
||||||
@ -731,7 +731,7 @@ module RSS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def initial_start_entry(tag_name, prefix, attrs, ns)
|
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 = Atom::Entry.new(@version, @encoding, @standalone)
|
||||||
@rss.do_validate = @do_validate
|
@rss.do_validate = @do_validate
|
||||||
|
@ -392,7 +392,7 @@ module RSS
|
|||||||
start_have_something_element(local, prefix, attrs, ns, next_class)
|
start_have_something_element(local, prefix, attrs, ns, next_class)
|
||||||
else
|
else
|
||||||
if !@do_validate or @ignore_unknown_element
|
if !@do_validate or @ignore_unknown_element
|
||||||
@proc_stack.push(nil)
|
@proc_stack.push(setup_next_element_in_unknown_element)
|
||||||
else
|
else
|
||||||
parent = "ROOT ELEMENT???"
|
parent = "ROOT ELEMENT???"
|
||||||
if current_class.tag_name
|
if current_class.tag_name
|
||||||
@ -423,13 +423,22 @@ module RSS
|
|||||||
[$1 || '', $2]
|
[$1 || '', $2]
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_ns(tag_name, prefix, ns, require_uri)
|
def check_ns(tag_name, prefix, ns, require_uri, ignore_unknown_element=nil)
|
||||||
unless _ns(ns, prefix) == require_uri
|
if _ns(ns, prefix) == require_uri
|
||||||
if @do_validate
|
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)
|
raise NSError.new(tag_name, prefix, require_uri)
|
||||||
else
|
else
|
||||||
# Force bind required URI with prefix
|
# Force bind required URI with prefix
|
||||||
@ns_stack.last[prefix] = require_uri
|
@ns_stack.last[prefix] = require_uri
|
||||||
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -456,9 +465,12 @@ module RSS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def start_have_something_element(tag_name, prefix, attrs, ns, klass)
|
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)
|
attributes = collect_attributes(tag_name, prefix, attrs, ns, klass)
|
||||||
@proc_stack.push(setup_next_element(tag_name, klass, attributes))
|
@proc_stack.push(setup_next_element(tag_name, klass, attributes))
|
||||||
|
else
|
||||||
|
@proc_stack.push(setup_next_element_in_unknown_element)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def collect_attributes(tag_name, prefix, attrs, ns, klass)
|
def collect_attributes(tag_name, prefix, attrs, ns, klass)
|
||||||
@ -525,6 +537,11 @@ module RSS
|
|||||||
@last_element = previous
|
@last_element = previous
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def setup_next_element_in_unknown_element
|
||||||
|
current_element, @last_element = @last_element, nil
|
||||||
|
Proc.new {@last_element = current_element}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
unless const_defined? :AVAILABLE_PARSER_LIBRARIES
|
unless const_defined? :AVAILABLE_PARSER_LIBRARIES
|
||||||
|
@ -507,6 +507,22 @@ EOR
|
|||||||
#{make_image}
|
#{make_image}
|
||||||
EOR
|
EOR
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user