I've had another look at lib/rss and the patch below is mostly doc
changes, but I have also changed the method to_class_name. My testing
with underscored names shows that it behaves the same, so hopefully
I have not broken anything. I think the code is clearer.
This is against:
brains hgs 82 %> ls -ld stable-snapshot.tar.gz
-rw-r--r-- 1 hgs staff 4467357 Jul 18 17:08 stable-snapshot.tar.gz
brains hgs 83 %> md5sum !$
md5sum stable-snapshot.tar.gz
a3bce2a5618af323c07ed68431ea1ef2 stable-snapshot.tar.gz
brains hgs 84 %>
HTH
Hugh
--- ./lib/rss/utils.rb.orig 2006-06-18 14:42:43.000000000 +0100
+++ ./lib/rss/utils.rb 2006-07-18 17:32:24.047018000 +0100
@@ -1,10 +1,10 @@
module RSS
module Utils
module_function
+
+ # Convert a name_with_underscores to CamelCase.
def to_class_name(name)
- name.split(/_/).collect do |part|
- "#{part[0, 1].upcase}#{part[1..-1]}"
- end.join("")
+ name.split(/_/).collect{|part| part.capitalize}.join("")
end
def get_file_and_line_from_caller(i=0)
@@ -12,11 +12,14 @@
[file, line.to_i]
end
+ # escape '&', '"', '<' and '>' for use in HTML.
def html_escape(s)
s.to_s.gsub(/&/, "&").gsub(/\"/, """).gsub(/>/, ">").gsub(/</, "<")
end
alias h html_escape
+ # If +value+ is an instance of class +klass+, return it, else
+ # create a new instance of +klass+ with value +value+.
def new_with_value_if_need(klass, value)
if value.is_a?(klass)
value
--- ./lib/rss/parser.rb.orig 2006-07-13 12:35:17.000000000 +0100
+++ ./lib/rss/parser.rb 2006-07-18 17:50:33.094732000 +0100
@@ -7,6 +7,11 @@
class NotWellFormedError < Error
attr_reader :line, :element
+
+ # Create a new NotWellFormedError for an error at +line+
+ # in +element+. If a block is given the return value of
+ # the block ends up in the error message.
+ #
def initialize(line=nil, element=nil)
message = "This is not well formed XML"
if element or line
@@ -85,13 +90,17 @@
end
private
+
+ # Try to get the XML associated with +rss+.
+ # Return +rss+ if it already looks like XML, or treat it as a URI,
+ # or a file to get the XML,
def normalize_rss(rss)
return rss if maybe_xml?(rss)
uri = to_uri(rss)
if uri.respond_to?(:read)
- uri.read
+ uri.read # FIXME? - do we care if the URI is tainted?
elsif !rss.tainted? and File.readable?(rss)
File.open(rss) {|f| f.read}
else