mirror of https://github.com/qt/qtbase.git
QSettings: Don't chop off trailing tabs that were actually part of a value.
This was done wrong when using the ini format. Task-number: QTBUG-22461 Change-Id: Ib9390460bce6138659cceac7e3cd25339ba5e9bb Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
3bfdacaaeb
commit
e66a878838
|
@ -774,11 +774,11 @@ void QSettingsPrivate::iniEscapedString(const QString &str, QByteArray &result,
|
|||
}
|
||||
}
|
||||
|
||||
inline static void iniChopTrailingSpaces(QString &str)
|
||||
inline static void iniChopTrailingSpaces(QString &str, int limit)
|
||||
{
|
||||
int n = str.size() - 1;
|
||||
QChar ch;
|
||||
while (n >= 0 && ((ch = str.at(n)) == QLatin1Char(' ') || ch == QLatin1Char('\t')))
|
||||
while (n >= limit && ((ch = str.at(n)) == QLatin1Char(' ') || ch == QLatin1Char('\t')))
|
||||
str.truncate(n--);
|
||||
}
|
||||
|
||||
|
@ -836,6 +836,7 @@ StSkipSpaces:
|
|||
// fallthrough
|
||||
|
||||
StNormal:
|
||||
int chopLimit = stringResult.length();
|
||||
while (i < to) {
|
||||
switch (str.at(i)) {
|
||||
case '\\':
|
||||
|
@ -873,6 +874,7 @@ StNormal:
|
|||
} else {
|
||||
// the character is skipped
|
||||
}
|
||||
chopLimit = stringResult.length();
|
||||
break;
|
||||
case '"':
|
||||
++i;
|
||||
|
@ -884,7 +886,7 @@ StNormal:
|
|||
case ',':
|
||||
if (!inQuotedString) {
|
||||
if (!currentValueIsQuoted)
|
||||
iniChopTrailingSpaces(stringResult);
|
||||
iniChopTrailingSpaces(stringResult, chopLimit);
|
||||
if (!isStringList) {
|
||||
isStringList = true;
|
||||
stringListResult.clear();
|
||||
|
@ -924,6 +926,8 @@ StNormal:
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!currentValueIsQuoted)
|
||||
iniChopTrailingSpaces(stringResult, chopLimit);
|
||||
goto end;
|
||||
|
||||
StHexEscape:
|
||||
|
@ -963,8 +967,6 @@ StOctEscape:
|
|||
}
|
||||
|
||||
end:
|
||||
if (!currentValueIsQuoted)
|
||||
iniChopTrailingSpaces(stringResult);
|
||||
if (isStringList)
|
||||
stringListResult.append(stringResult);
|
||||
return isStringList;
|
||||
|
|
|
@ -128,6 +128,7 @@ private slots:
|
|||
void testEmptyData();
|
||||
void testResourceFiles();
|
||||
void testRegistryShortRootNames();
|
||||
void trailingWhitespace();
|
||||
#ifdef Q_OS_MAC
|
||||
void fileName();
|
||||
#endif
|
||||
|
@ -2030,6 +2031,23 @@ void tst_QSettings::testRegistryShortRootNames()
|
|||
#endif
|
||||
}
|
||||
|
||||
void tst_QSettings::trailingWhitespace()
|
||||
{
|
||||
{
|
||||
QSettings s("tst_QSettings_trailingWhitespace");
|
||||
s.setValue("trailingSpace", "x ");
|
||||
s.setValue("trailingTab", "x\t");
|
||||
s.setValue("trailingNewline", "x\n");
|
||||
}
|
||||
{
|
||||
QSettings s("tst_QSettings_trailingWhitespace");
|
||||
QCOMPARE(s.value("trailingSpace").toString(), QLatin1String("x "));
|
||||
QCOMPARE(s.value("trailingTab").toString(), QLatin1String("x\t"));
|
||||
QCOMPARE(s.value("trailingNewline").toString(), QLatin1String("x\n"));
|
||||
s.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QSettings::fromFile_data()
|
||||
{
|
||||
populateWithFormats();
|
||||
|
|
Loading…
Reference in New Issue