I'm trying to use Redcloth in my Ruby app, and it's giving me a wrong number of arguments (3 for 2)
error even though I only have two arguments.
Here's my code:
def self.cleanup(string)
if string == "" || string == nil
""
else
string = self.iconvert(string, "ascii", "utf8")
RedCloth.include(RedCloth::Formatters::HTML)
redcloth = RedCloth.new(string)
redcloth.html_esc(string)
string = string.strip
string = string.gsub(/''/,"\"")
string = string.gsub(/\r/," ")
string = string.gsub(/\n/," ")
string = string.gsub(/\<br \/\>/," ")
string = string.gsub(/\<br\/\>/," ")
string = string.gsub(/ /," ")
redcloth.clean_html(string, {})
string
end
end
This is the source code: http://redcloth.rubyforge.org/classes/RedCloth/Formatters/HTML.html#M000052
def clean_html( text, allowed_tags = BASIC_TAGS )
text.gsub!( /<!\[CDATA\[/, '' )
text.gsub!( /<(\/*)([A-Za-z]\w*)([^>]*?)(\s?\/?)>/ ) do |m|
raw = $~
tag = raw[2].downcase
if allowed_tags.has_key? tag
pcs = [tag]
allowed_tags[tag].each do |prop|
['"', "'", ''].each do |q|
q2 = ( q != '' ? q : '\s' )
if raw[3] =~ /#{prop}\s*=\s*#{q}([^#{q2}]+)#{q}/i
attrv = $1
next if (prop == 'src' or prop == 'href') and not attrv =~ %r{^(http|https|ftp):}
pcs << "#{prop}=\"#{attrv.gsub('"', '\\"')}\""
break
end
end
Here's my log:
I, [2013-07-16T12:22:53.095073 #12321] INFO -- : wrong number of arguments (3 for 2)
I, [2013-07-16T12:22:53.095281 #12321] INFO -- : /home/emai/.rvm/gems/ruby-1.9.3-p448@edmund/gems/RedCloth-4.2.9/lib/redcloth/formatters/base.rb:46:in `method_missing'
You're getting the error because the definition of method_missing
in that Redcloth source file (base.rb) is defined with just two arguments (and no splat operator) and you are invoking an undefined method with two arguments which, when added to the method name, results in three arguments being passed to method_missing
.
The offending call appears to be the call to redcloth.clean_html
. As you noted in your comment, clean_html
is a private method, so it's not accessible to you through the normal object.method
invocation mechanism.