Skip to content

Instantly share code, notes, and snippets.

@repeatedly
Last active December 13, 2015 19:19
Show Gist options
  • Save repeatedly/4961986 to your computer and use it in GitHub Desktop.
Save repeatedly/4961986 to your computer and use it in GitHub Desktop.
No exception after applied String#encode.
str = "\xff"
str.force_encoding('UTF-8')
begin
str =~ /a/
rescue => e
p e # invalid byte sequence in UTF-8 (ArgumentError)
end
str = str.encode("UTF-8", "UTF-8")
begin
str =~ /a/ # no throw, why?
rescue => e
p e
end
@repeatedly
Copy link
Author

Tested with ruby 1.9.3p385 (2013-02-06 revision 39114) [x86_64-darwin12.2.1]

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