Open
Description
Describe the bug
Applying builtins.toXML
to a string with invalid UTF-8 encoding returns
"<?xml version='1.0' encoding='utf-8'?>\n<expr>\n <string value=\"[...]\" />\n</expr>\n"
where [...]
is the input string with invalid UTF-8 encoding.
Steps To Reproduce
- Download test file:
wget -O - https://github.com/flenniken/utf8tests/raw/refs/heads/main/utf8tests.bin | head -n 208 > utf8tests.bin
- Evaluate the following Nix expression, e.g. in
nix repl
:
builtins.toXML (builtins.readFile ./utf8tests.bin)
- The output contains the invalid UTF-8 input string.
Expected behavior
Either builtins.readFile
or builtins.toXML
should fail and a proper error message should be displayed.
Additional context
Related to issue #12060.
Checklist
- checked latest Nix manual (source)
- checked open bug issues and pull requests for possible duplicates
Add 👍 to issues you find important.