From c9c848e99555f816aa183e7dad426e3151e0f51d Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Tue, 2 Jan 2018 18:15:38 +0100 Subject: [PATCH] Fix wrong BOM detection This fixes a bug introduced in 27c657902e354b11fb5778cc09518a95d37d3698. In that commit we are checking if a string starts with a Unicode BOM and remove the BOM if necessary. Apparently though Qt's startsWith() function doesn't work as exected here, so it's changed to a manual comparison in this commit which seems to work fine. The first person who can explain that behaviour to me gets a free beer if we meet in person. See issue #1279. See issue #1282. --- src/Data.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Data.cpp b/src/Data.cpp index 33254219..9cd6f556 100644 --- a/src/Data.cpp +++ b/src/Data.cpp @@ -34,16 +34,16 @@ bool startsWithBom(const QByteArray& data) QByteArray removeBom(QByteArray& data) { - if(data.startsWith("\xEF\xBB\xBF")) + if(data.left(3) == QByteArray("\xEF\xBB\xBF")) { QByteArray bom = data.left(3); data.remove(0, 3); return bom; - } else if(data.startsWith("\xFE\xFF") || data.startsWith("\xFF\xFE")) { + } else if(data.left(2) == QByteArray("\xFE\xFF") || data.left(2) == QByteArray("\xFF\xFE")) { QByteArray bom = data.left(2); data.remove(0, 2); return bom; - } else if(data.startsWith("\x00\x00\xFE\xFF") || data.startsWith("\xFF\xFE\x00\x00")) { + } else if(data.left(4) == QByteArray("\x00\x00\xFE\xFF") || data.left(4) == QByteArray("\xFF\xFE\x00\x00")) { QByteArray bom = data.left(4); data.remove(0, 4); return bom;