Permalink
Browse files

Force encoding as needed. Works correctly in ruby 1.9.3

  • Loading branch information...
sdsykes committed Mar 22, 2012
1 parent 4cb3936 commit f2f64f893304fd94e28fd486bec5e8fbe80771a0
Showing with 10 additions and 1 deletion.
  1. +10 −1 lib/fastimage.rb
View
@@ -246,14 +246,23 @@ 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]
raise MoreCharsNeeded
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

0 comments on commit f2f64f8

Please sign in to comment.