Skip to content

Instantly share code, notes, and snippets.

@solon
Created April 2, 2012 01:04
Show Gist options
  • Save solon/2279844 to your computer and use it in GitHub Desktop.
Save solon/2279844 to your computer and use it in GitHub Desktop.
padrino-cache ArgumentError: invalid byte sequence in UTF-8
require 'redis'
require "active_support/core_ext/string/multibyte"
require "active_support/core_ext/object/blank"
redis = Redis.new
good_string = "...............................................................................\n\n...............................................................................\n\n...............................................................................\n\n...............................................................................\n\n\n.........................................................."
bad_string = "...............................................................................\n\n...............................................................................\n\n...............................................................................\n\n...............................................................................\n\n\n..........................................................\n"
foo_dump = Marshal.dump({:response_buffer => good_string, :content_type => :html})
bar_dump = Marshal.dump({:response_buffer => bad_string, :content_type => :html})
foo_dump.is_utf8? # => true
bar_dump.is_utf8? # => false
foo_dump.blank? # => false
bar_dump.blank? # => false
redis.set "foo", foo_dump
redis.set "bar", bar_dump
foo_value = redis.get "foo"
# => "\u0004\b{\a:\u0014response_bufferI\"\u0002\u007F\u0001...[etc.]...\u0006:\u0006ET:\u0011content_type:\thtml"
bar_value = redis.get "bar"
# => "\u0004\b{\a:\u0014response_bufferI\"\u0002\x80\u0001...[etc.]...\n\u0006:\u0006ET:\u0011content_type:\thtml"
foo_value.is_utf8? # => true
bar_value.is_utf8? # => false
foo_value.blank? # => false
bar_value.blank? # => ArgumentError: invalid byte sequence in UTF-8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment