git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] utf8: add comment explaining why BOMs are rejected

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Dec 27, 2018, 02:17 UTC
Message-ID
<20181227021734.528629-3-sandals@crustytoothpaste.net>
In-Reply-To
<20181227021734.528629-1-sandals@crustytoothpaste.net>

A source of confusion for many Git users is why UTF-16LE and UTF-16BE do not allow a BOM, instead treating it as a ZWNBSP, according to the Unicode FAQ[0]. Explain in a comment why we cannot allow that to occur due to our use of UTF-8 internally.

[0] https://unicode.org/faq/utf_bom.html#bom9
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 utf8.c | 7 +++++++
 1 file changed, 7 insertions(+)
diff --git a/utf8.c b/utf8.c
index eb78587504..22af2c485a 100644
--- a/utf8.c
+++ b/utf8.c
@@ -571,6 +571,13 @@ static const char utf16_le_bom[] = {'\xFF', '\xFE'};
 static const char utf32_be_bom[] = {'\0', '\0', '\xFE', '\xFF'};
 static const char utf32_le_bom[] = {'\xFF', '\xFE', '\0', '\0'};
 
+/*
+ * We check here for a forbidden BOM. When using UTF-16BE or UTF-16LE, a BOM is
+ * not allowed by RFC 2781, and any U+FEFF would be treated as a ZWNBSP, not a
+ * BOM. However, because we encode into UTF-8 internally, we cannot allow that
+ * character to occur as a ZWNBSP, since when encoded into UTF-8 it would be
+ * interpreted as a BOM.
+ */
 int has_prohibited_utf_bom(const char *enc, const char *data, size_t len)
 {
 	return (
Previous: brian m. carlsonNext: Johannes Sixt
Message 3 of 12 in “Improve documentation on UTF-16”
  1. 0/2 Improve documentation on UTF-16brian m. carlson, Dec 27, 2018
  2. 1/2 Documentation: document UTF-16-related behaviorbrian m. carlson, Dec 27, 2018
  3. 2/2 utf8: add comment explaining why BOMs are rejectedbrian m. carlson, Dec 27, 2018
  4. Johannes SixtDec 27, 2018
  5. brian m. carlsonDec 27, 2018
  6. Johannes SixtDec 27, 2018
  7. brian m. carlsonDec 27, 2018
  8. Johannes SixtDec 28, 2018
  9. Philip OakleyDec 28, 2018
  10. Ævar Arnfjörð BjarmasonDec 28, 2018
  11. Philip OakleyDec 28, 2018
  12. brian m. carlsonDec 29, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.