Skip to content

Instantly share code, notes, and snippets.

@bjfish
Created December 23, 2016 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjfish/a1f3de2969b7d77c080c44170745c009 to your computer and use it in GitHub Desktop.
Save bjfish/a1f3de2969b7d77c080c44170745c009 to your computer and use it in GitHub Desktop.
Scrub Bug?
irb(main):017:0> "\xD8\x00\x30\x42".force_encoding(Encoding::UTF_16BE).scrub("dog".encode(Encoding::UTF_16BE)) { "cat".encode(Encoding::UTF_16BE) }
=> "dog\u3042"
irb(main):018:0> "\xD8\x00\x30\x42".scrub("dog") { "cat" }
=> "cat\u00000B"
@bjfish
Copy link
Author

bjfish commented Dec 23, 2016

Also buggy:

irb(main):007:0> "\xD8\x00\x30\x42".force_encoding(Encoding::UTF_16BE).scrub  { |b| puts "bytes:#{b}"; "cat".encode(Encoding::UTF_16BE) }

Yielded values might be suspicious

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment