htmlentities icon indicating copy to clipboard operation
htmlentities copied to clipboard

"\xE2" from ASCII-8BIT to UTF-8

Open noahkconley opened this issue 6 years ago • 1 comments

Getting this issue from within the HTMLEntities#decode method from a decrypted csv file. Is there a workaround for this?

noahkconley avatar Sep 21 '18 21:09 noahkconley

The problem is that the underlying Ruby code to encode the strings is not handling undefined or invalid values, so the error bubbles up. This is something the gem author could fix (or someone could submit a PR to fix this).

See: https://ruby-doc.org/core-2.5.3/String.html#method-i-encode

# lib/htmlentities/decoder.rb
#...snip
private

def prepare(string) #:nodoc:
  string.to_s.encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: '?')
end

#...snip

cfurrow avatar Nov 27 '21 14:11 cfurrow