From 4b5b5c6238fda67d81e7def0dde8bad701cf7972 Mon Sep 17 00:00:00 2001 From: mgrojo Date: Sun, 3 Mar 2019 14:25:49 +0100 Subject: [PATCH] Detect data with embedded zeros as binary also for ISO-8859 See issues #1772 and #1773 --- src/Data.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Data.cpp b/src/Data.cpp index 1d8344bd..8c1067d0 100644 --- a/src/Data.cpp +++ b/src/Data.cpp @@ -17,10 +17,11 @@ bool isTextOnly(QByteArray data, const QString& encoding, bool quickTest) if(startsWithBom(data)) return true; - // We can assume that the default encoding (UTF-8) cannot contain character zero. - // This has to be checked explicitly because toUnicode() is ignoring bytes beyond - // the zero. - if(encoding.isEmpty() && data.contains('\0')) + // We can assume that the default encoding (UTF-8) and all the ISO-8859 + // cannot contain character zero. + // This has to be checked explicitly because toUnicode() is using zero as + // a terminator for these encodings. + if((encoding.isEmpty() || encoding.startsWith("ISO-8859")) && data.contains('\0')) return false; // Truncate to the first couple of bytes for quick testing