Skip to content

Instantly share code, notes, and snippets.

@drbrain

drbrain/test.rb Secret

Created November 6, 2013 04:02
Show Gist options
  • Save drbrain/0b255dcf5976978a1243 to your computer and use it in GitHub Desktop.
Save drbrain/0b255dcf5976978a1243 to your computer and use it in GitHub Desktop.
# coding: BINARY
# simulate broken string
s = "a b c \xE9 e".force_encoding Encoding::UTF_8
t = s.encode Encoding::UTF_16, invalid: :replace, undef: :replace, replace: ''
p t: t
u = t.encode Encoding::UTF_8
p u: u
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment