Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Force encoding as needed. Works correctly in ruby 1.9.3

  • Loading branch information...
commit f2f64f893304fd94e28fd486bec5e8fbe80771a0 1 parent 4cb3936
@sdsykes authored
Showing with 10 additions and 1 deletion.
  1. +10 −1 lib/fastimage.rb
View
11 lib/fastimage.rb
@@ -246,6 +246,14 @@ def parse_size
send("parse_size_for_#{@type}")
end
+ def has_encoding?
+ if @has_encoding.nil?
+ @has_encoding = String.new.respond_to? :force_encoding
+ else
+ @has_encoding
+ end
+ end
+
def get_chars(n)
if @strpos + n - 1 >= @str.size
@unused_str = @str[@strpos..-1]
@@ -253,7 +261,8 @@ def get_chars(n)
else
result = @str[@strpos..(@strpos + n - 1)]
@strpos += n
- result
+ # we are dealing with bytes here, so force the encoding
+ has_encoding? ? result.force_encoding("ASCII-8BIT") : result
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.