Fix wrong BOM detection

This fixes a bug introduced in 27c657902e.
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.
This commit is contained in:
Martin Kleusberg
2018-01-02 18:15:38 +01:00
parent 117af5aeeb
commit c9c848e995
+3 -3
View File
@@ -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;