Reject malformed UTF-8 in CSV imports before parsing with TextDecoder fatal mode
A CSV file can have correct columns yet contain corrupted text, because damage can occur before the parser ever sees the data. JavaScript's TextDecoder silently replaces invalid byte sequences with the U+FFFD replacement character by default, which can alter values like lookup keys without warning. Setting the fatal option to true makes decoding throw an error instead, allowing import workflows to reject damaged bytes. The article recommends checking file size before reading, keeping prior data and showing an actionable error on failure, and avoiding automatic retries under other encodings. It also notes that strict decoding only confirms byte validity, not correct encoding or valid CSV, so syntax and domain checks must follow separately.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in