Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed URI.escape and URI.unescape warnings in 1.9.2 #244

Merged
merged 1 commit into from May 23, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/mail/utilities.rb
Expand Up @@ -116,11 +116,15 @@ def escape_paren( str )
end

def uri_escape( str )
URI.escape(str)
uri_parser.escape(str)
end

def uri_unescape( str )
URI.unescape(str)
uri_parser.unescape(str)
end

def uri_parser
@uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI
end

# Matches two objects with their to_s values case insensitively
Expand Down
8 changes: 6 additions & 2 deletions lib/mail/version_specific/ruby_1_9.rb
Expand Up @@ -76,15 +76,19 @@ def Ruby19.q_value_decode(str)
end

def Ruby19.param_decode(str, encoding)
string = URI.unescape(str)
string = uri_parser.unescape(str)
string.force_encoding(encoding) if encoding
string
end

def Ruby19.param_encode(str)
encoding = str.encoding.to_s.downcase
language = Configuration.instance.param_encode_language
"#{encoding}'#{language}'#{URI.escape(str)}"
"#{encoding}'#{language}'#{uri_parser.escape(str)}"
end

def Ruby19.uri_parser
@uri_parser ||= URI::Parser.new
end

# mails somtimes includes invalid encodings like iso885915 or utf8 so we transform them to iso885915 or utf8
Expand Down
3 changes: 2 additions & 1 deletion spec/mail/attachments_list_spec.rb
Expand Up @@ -180,7 +180,8 @@ def check_decoded(actual, expected)

it "should provide a URL escaped content_id (without brackets) for use inside an email" do
@inline = @mail.attachments['test.gif'].cid
@inline.should == URI.escape(@cid.gsub(/^</, '').gsub(/>$/, ''))
uri_parser = URI.const_defined?(:Parser) ? URI::Parser.new : URI
@inline.should == uri_parser.escape(@cid.gsub(/^</, '').gsub(/>$/, ''))
end
end

Expand Down
3 changes: 2 additions & 1 deletion spec/mail/utilities_spec.rb
Expand Up @@ -320,7 +320,8 @@
end

it "should have a wrapper on URI.unescape" do
uri_unescape("@?@!").should == URI.unescape("@?@!")
uri_parser = URI.const_defined?(:Parser) ? URI::Parser.new : URI
uri_unescape("@?@!").should == uri_parser.unescape("@?@!")
end
end

Expand Down