Skip to content

Commit

Permalink
Detect data with embedded zeros as binary also for ISO-8859
Browse files Browse the repository at this point in the history
See issues #1772 and #1773
  • Loading branch information
mgrojo committed Mar 12, 2019
1 parent b412f9d commit d0fef81
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d0fef81

Please sign in to comment.