ruby-changes:11796
From: kou <ko1@a...>
Date: Sat, 16 May 2009 18:27:40 +0900 (JST)
Subject: [ruby-changes:11796] Ruby:r23451 (trunk): * lib/rss/parser.rb, test/test_parser_1.0.rb: fix foaf:Image
kou 2009-05-16 18:25:59 +0900 (Sat, 16 May 2009) New Revision: 23451 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=23451 Log: * lib/rss/parser.rb, test/test_parser_1.0.rb: fix foaf:Image element causes parse error even if ignore_unknown_element mode. Modified files: trunk/ChangeLog trunk/lib/rss/0.9.rb trunk/lib/rss/1.0.rb trunk/lib/rss/atom.rb trunk/lib/rss/parser.rb trunk/test/rss/test_parser_1.0.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 23450) +++ ChangeLog (revision 23451) @@ -1,3 +1,8 @@ +Sat May 16 18:26:42 2009 Kouhei Sutou <kou@c...> + + * 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@c...> * lib/rss/maker.rb, lib/rss/maker/0.9.rb, Index: lib/rss/parser.rb =================================================================== --- lib/rss/parser.rb (revision 23450) +++ lib/rss/parser.rb (revision 23451) @@ -392,7 +392,7 @@ 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 @@ [$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 @@ end def start_have_something_element(tag_name, prefix, attrs, ns, klass) - 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)) + 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 @@ @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 Index: lib/rss/1.0.rb =================================================================== --- lib/rss/1.0.rb (revision 23450) +++ lib/rss/1.0.rb (revision 23451) @@ -436,7 +436,7 @@ 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 Index: lib/rss/atom.rb =================================================================== --- lib/rss/atom.rb (revision 23450) +++ lib/rss/atom.rb (revision 23451) @@ -716,7 +716,7 @@ 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 @@ 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 Index: lib/rss/0.9.rb =================================================================== --- lib/rss/0.9.rb (revision 23450) +++ lib/rss/0.9.rb (revision 23451) @@ -411,7 +411,7 @@ 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 Index: test/rss/test_parser_1.0.rb =================================================================== --- test/rss/test_parser_1.0.rb (revision 23450) +++ test/rss/test_parser_1.0.rb (revision 23451) @@ -507,6 +507,22 @@ #{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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/