Fix QSettings parsing of spaces after comment lines

[ChangeLog][QtCore][QSettings] Fixed QSettings parsing of blank spaces
after comment lines in INI-style configuration files.

Fixes: QTBUG-72007
Change-Id: Idd0c85a4e7b64f9c9c7dfffd156c5b219f3b5c0a
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
bb10
Thiago Macieira 2018-12-01 18:02:52 -06:00
parent 9d4406f49a
commit 962bded90f
4 changed files with 51 additions and 0 deletions

View File

@ -1634,6 +1634,8 @@ bool QConfFileSettingsPrivate::readIniLine(const QByteArray &data, int &dataPos,
char ch;
while (i < dataLen && (((ch = data.at(i)) != '\n') && ch != '\r'))
++i;
while (i < dataLen && charTraits[uchar(data.at(i))] & Space)
++i;
lineStart = i;
} else if (!inQuotes) {
--i;

View File

@ -7,5 +7,6 @@
<file>resourcefile5.ini</file>
<file>resourcefile6.plist</file>
<file>bom.ini</file>
<file>withcomments.ini</file>
</qresource>
</RCC>

View File

@ -187,6 +187,7 @@ private slots:
void bom();
void embeddedZeroByte_data();
void embeddedZeroByte();
void spaceAfterComment();
void testXdg();
private:
@ -764,6 +765,34 @@ void tst_QSettings::embeddedZeroByte()
}
}
void tst_QSettings::spaceAfterComment()
{
QSettings settings(QFINDTESTDATA("withcomments.ini"), QSettings::IniFormat);
QCOMPARE(settings.status(), QSettings::NoError);
QStringList groups = settings.childGroups();
QVERIFY(groups.contains("Regular"));
QVERIFY(groups.contains("WithSpaces"));
QVERIFY(groups.contains("WithTab"));
QVERIFY(groups.contains("SpacedGroup"));
settings.beginGroup("Regular");
QCOMPARE(settings.value("bar"), QVariant(2));
settings.endGroup();
settings.beginGroup("WithSpaces");
QCOMPARE(settings.value("bar"), QVariant(4));
settings.endGroup();
settings.beginGroup("WithTab");
QCOMPARE(settings.value("bar"), QVariant(6));
settings.endGroup();
settings.beginGroup("SpacedGroup");
QCOMPARE(settings.value("bar"), QVariant(7));
settings.endGroup();
}
void tst_QSettings::testErrorHandling_data()
{
QTest::addColumn<int>("filePerms"); // -1 means file should not exist

View File

@ -0,0 +1,19 @@
; -*- conf -*-
; If you edit this file, make sure, that "WithSpaces" has spaces and that
; "WithTab" has one tab
[Regular]
;bar = 1
bar = 2
[WithSpaces]
;bar = 3
bar = 4
[WithTab]
;bar = 5
bar = 6
; [SpacedGroup]
[SpacedGroup]
bar = 7