> ## Documentation Index
> Fetch the complete documentation index at: https://loadwise.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# lossy-same-file-text-rewrite

> A caller-selected file is decoded permissively as UTF-8 and overwritten after a text edit.

## What it flags

A synchronous Node filesystem read decodes a caller-selected file as UTF-8. The rule follows an unchanged string path parameter from an exported function or public method of an exported class. It recognizes an explicit UTF-8 read or a buffer decoded with `toString`, followed by `replace` or `replaceAll` and a synchronous write to the same path. Node's permissive decoding can replace invalid UTF-8 with U+FFFD, which changes bytes outside the intended edit. The finding appears with `--include-contextual`.

## How to review or fix

Check the application's input encoding contract. If invalid UTF-8 must be rejected, validate with a fatal decoder before writing and preserve any required byte order mark. If other encodings are supported, decode and encode using the file's known encoding.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.