Permalink
Browse files

Quick hack for Ruby 2.0 compatibility (Only valid for ruby 1.9 and up)

  • Loading branch information...
1 parent 0572f4b commit b82de3b0f408f0af5d79af59be9b2381db72ad41 @melindaweathers committed May 13, 2013
Showing with 8 additions and 23 deletions.
  1. +8 −23 lib/aws/s3/extensions.rb
View
@@ -61,34 +61,19 @@ def underscore
tr("-", "_").downcase
end unless public_method_defined? :underscore
- if RUBY_VERSION >= '1.9'
- def valid_utf8?
- dup.force_encoding('UTF-8').valid_encoding?
- end
- else
- def valid_utf8?
- scan(Regexp.new('[^\x00-\xa0]', nil, 'u')) { |s| s.unpack('U') }
- true
- rescue ArgumentError
- false
- end
+ def valid_utf8?
+ dup.force_encoding('UTF-8').valid_encoding?
end
# All paths in in S3 have to be valid unicode so this takes care of
# cleaning up any strings that aren't valid utf-8 according to String#valid_utf8?
- if RUBY_VERSION >= '1.9'
- def remove_extended!
- sanitized_string = ''
- each_byte do |byte|
- character = byte.chr
- sanitized_string << character if character.ascii_only?
- end
- sanitized_string
- end
- else
- def remove_extended!
- gsub!(/[\x80-\xFF]/) { "%02X" % $&[0] }
+ def remove_extended!
+ sanitized_string = ''
+ each_byte do |byte|
+ character = byte.chr
+ sanitized_string << character if character.ascii_only?
end
+ sanitized_string
end
def remove_extended

0 comments on commit b82de3b

Please sign in to comment.