07-19-2023, 01:29 AM
I have an Rails application surviving from migrations since Rails version 1 and I would like to ignore **all** invalid byte sequences on it, to keep the backwards compatibility.
**I can't know the input encoding**.
Exemple:
> "- Men\xFC -".split("n")
ArgumentError: invalid byte sequence in UTF-8
from (irb):4:in `split'
from (irb):4
from /home/fotanus/.rvm/rubies/ruby-2.0.0-rc2/bin/irb:16:in `<main>'
I can overcome this problem in one line, by using the following, for example:
> "- Men\xFC -".unpack("C*").pack("U*").split("n")
=> ["- Me", "ü -"]
However I would like to always ignore the invalid byte sequences and disable this errors. On Ruby itself or in Rails.
**I can't know the input encoding**.
Exemple:
> "- Men\xFC -".split("n")
ArgumentError: invalid byte sequence in UTF-8
from (irb):4:in `split'
from (irb):4
from /home/fotanus/.rvm/rubies/ruby-2.0.0-rc2/bin/irb:16:in `<main>'
I can overcome this problem in one line, by using the following, for example:
> "- Men\xFC -".unpack("C*").pack("U*").split("n")
=> ["- Me", "ü -"]
However I would like to always ignore the invalid byte sequences and disable this errors. On Ruby itself or in Rails.