git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: git@vger.kernel.org
Cc: "Lars Schneider" <larsxschneider@gmail.com>,
	"Torsten Bögershausen" <tboegi@web.de>
Subject: [PATCH 2/2] utf8: add comment explaining why BOMs are rejected
Date: Thu, 27 Dec 2018 02:17:34 +0000	[thread overview]
Message-ID: <20181227021734.528629-3-sandals@crustytoothpaste.net> (raw)
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 (

  parent reply	other threads:[~2018-12-27  2:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-27  2:17 [PATCH 0/2] Improve documentation on UTF-16 brian m. carlson
2018-12-27  2:17 ` [PATCH 1/2] Documentation: document UTF-16-related behavior brian m. carlson
2018-12-27  2:17 ` brian m. carlson [this message]
2018-12-27 10:06 ` [PATCH 0/2] Improve documentation on UTF-16 Johannes Sixt
2018-12-27 16:43   ` brian m. carlson
2018-12-27 19:55     ` Johannes Sixt
2018-12-27 23:45       ` brian m. carlson
2018-12-28  8:59         ` Johannes Sixt
2018-12-28 20:31           ` Philip Oakley
2018-12-28  8:46 ` Ævar Arnfjörð Bjarmason
2018-12-28 20:35   ` Philip Oakley
2018-12-29 23:17   ` brian m. carlson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181227021734.528629-3-sandals@crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=git@vger.kernel.org \
    --cc=larsxschneider@gmail.com \
    --cc=tboegi@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).