Byte Order Marks at the Start of Text
Some Unicode formats use an initial mark to convey an encoding convention. UTF-8 can optionally use its byte representation as a signature.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Identify a UTF-8 signature
The bytes EF BB BF at the beginning can encode U+FEFF as a UTF-8 signature. UTF-8 needs no byte-order choice for multibyte code points. Review byte order for formats where ordering of wider units does matter.
Choose a reader policy
One reader may remove the initial signature and another may expose a character in the first field. Test files with and without it under the claimed format. Whitespace and fields show why unexpected leading characters can change text comparisons.[1]
Inspect a known prefix without assuming it is allowed
Bytes EF BB BF at the beginning of a UTF-8 file encode U+FEFF and can mark the encoding by convention. UTF-8 itself has no alternative byte order. A decoder consuming the marker by policy can yield the text after it, whereas ordinary decoding may keep the character. See byte order.
Bytes: EF BB BF 69 64
Ordinary UTF-8: U+FEFF followed by "id"
Signature-aware decoding at start: "id"
Choose behavior from the format that contains the text
A CSV header read without consuming an expected marker may become a different key. A protocol may forbid adding the marker even if parsers can tolerate it. Test files with and without it, and distinguish its leading position from later occurrences.