summaryrefslogtreecommitdiff
path: root/lib/rss/rss.rb
diff options
context:
space:
mode:
authorkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-06-18 09:22:12 +0000
committerkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-06-18 09:22:12 +0000
commitc849d2692ba964baabf536024a24b164ca622510 (patch)
treeab54ab154fa8ec3327adc9dbbf17fe828e595539 /lib/rss/rss.rb
parente49a4c952cfdf32abf3d6ba946f94d152dae988d (diff)
* lib/rss/rss.rb: improved ignore_unknown_element
handling. RSS::NotExpectedTagError provides tag URI. * lib/rss/parser.rb: ditto. * lib/rss/0.9.rb: ditto. * lib/rss/1.0.rb: ditto. * lib/rss/content.rb: ditto. * lib/rss/dublincore.rb: ditto. * lib/rss/image.rb: ditto. * lib/rss/syndication.rb: ditto. * lib/rss/taxonomy.rb: ditto. * lib/rss/trackback.rb: ditto. * test/rss/rss-assertions.rb: checked URI of not expected tag too. * test/rss/test_parser.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@10313 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rss/rss.rb')
-rw-r--r--lib/rss/rss.rb30
1 files changed, 16 insertions, 14 deletions
diff --git a/lib/rss/rss.rb b/lib/rss/rss.rb
index b079661ec0..b1e1b55e4e 100644
--- a/lib/rss/rss.rb
+++ b/lib/rss/rss.rb
@@ -87,10 +87,10 @@ module RSS
end
class NotExpectedTagError < InvalidRSSError
- attr_reader :tag, :parent
- def initialize(tag, parent)
- @tag, @parent = tag, parent
- super("tag <#{tag}> is not expected in tag <#{parent}>")
+ attr_reader :tag, :uri, :parent
+ def initialize(tag, uri, parent)
+ @tag, @uri, @parent = tag, uri, parent
+ super("tag <{#{uri}}#{tag}> is not expected in tag <#{parent}>")
end
end
# For backward compatibility :X
@@ -585,14 +585,14 @@ EOC
end
end
- def validate
+ def validate(ignore_unknown_element=true)
validate_attribute
- __validate
+ __validate(ignore_unknown_element)
end
- def validate_for_stream(tags)
+ def validate_for_stream(tags, ignore_unknown_element=true)
validate_attribute
- __validate(tags, false)
+ __validate(ignore_unknown_element, tags, false)
end
def setup_maker(maker)
@@ -744,7 +744,7 @@ EOC
[]
end
- def __validate(tags=_tags, recursive=true)
+ def __validate(ignore_unknown_element, tags=_tags, recursive=true)
if recursive
children.compact.each do |child|
child.validate
@@ -756,11 +756,13 @@ EOC
self.class::NSPOOL.each do |prefix, uri|
if tags.has_key?(uri) and !must_call_validators.has_key?(uri)
meth = "#{prefix}_validate"
- __send__(meth, tags[uri]) if respond_to?(meth, true)
+ if respond_to?(meth, true)
+ __send__(meth, ignore_unknown_element, tags[uri], uri)
+ end
end
end
must_call_validators.each do |uri, prefix|
- __send__("#{prefix}_validate", tags[uri])
+ __send__("#{prefix}_validate", ignore_unknown_element, tags[uri], uri)
end
end
@@ -784,7 +786,7 @@ EOC
rv.join("\n")
end
- def _validate(tags, model=self.class.model)
+ def _validate(ignore_unknown_element, tags, uri, model=self.class.model)
count = 1
do_redo = false
not_shift = false
@@ -869,8 +871,8 @@ EOC
end
- if !tags.nil? and !tags.empty?
- raise NotExpectedTagError.new(tag, tag_name)
+ if !ignore_unknown_element and !tags.nil? and !tags.empty?
+ raise NotExpectedTagError.new(tags.first, uri, tag_name)
end
end