Skip to content

Commit

Permalink
Force encoding as needed. Works correctly in ruby 1.9.3
Browse files Browse the repository at this point in the history
  • Loading branch information
sdsykes committed Mar 22, 2012
1 parent 4cb3936 commit f2f64f8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/fastimage.rb
Expand Up @@ -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

Expand Down

0 comments on commit f2f64f8

Please sign in to comment.