summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Strickroth <email@cs-ware.de>2014-11-13 19:30:47 +0100
committerCarlos Martín Nieto <cmn@dwim.me>2015-03-21 21:12:08 +0100
commit8693335b67750fc8e927b153ecffe0de361ce277 (patch)
tree1f2f0d13d36fad264bbe7ebcd0252bb3e36cc6a9
parent53fc54d5c72068410d8508789dc275dcdd4eaac4 (diff)
downloadlibgit2-8693335b67750fc8e927b153ecffe0de361ce277.tar.gz
Make binary detection work similar to vanilla git
Main change: Don't treat chars > 128 as non-printable (common in UTF-8 files) Signed-off-by: Sven Strickroth <email@cs-ware.de>
-rw-r--r--src/buf_text.c5
-rw-r--r--tests/core/buffer.c2
2 files changed, 5 insertions, 2 deletions
diff --git a/src/buf_text.c b/src/buf_text.c
index cead599f4..cb3661edb 100644
--- a/src/buf_text.c
+++ b/src/buf_text.c
@@ -191,7 +191,10 @@ bool git_buf_text_is_binary(const git_buf *buf)
while (scan < end) {
unsigned char c = *scan++;
- if (c > 0x1F && c < 0x7F)
+ /* Printable characters are those above SPACE (0x1F) excluding DEL,
+ * and including BS, ESC and FF.
+ */
+ if ((c > 0x1F && c != 127) || c == '\b' || c == '\033' || c == '\014')
printable++;
else if (c == '\0')
return true;
diff --git a/tests/core/buffer.c b/tests/core/buffer.c
index 87dec4607..d28aa218f 100644
--- a/tests/core/buffer.c
+++ b/tests/core/buffer.c
@@ -830,7 +830,7 @@ void test_core_buffer__classify_with_utf8(void)
cl_assert(!git_buf_text_contains_nul(&b));
b.ptr = data1; b.size = b.asize = data1len;
- cl_assert(git_buf_text_is_binary(&b));
+ cl_assert(!git_buf_text_is_binary(&b));
cl_assert(!git_buf_text_contains_nul(&b));
b.ptr = data2; b.size = b.asize = data2len;