summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2014-06-04 11:52:37 (GMT)
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-06-12 16:45:12 (GMT)
commit8fa348a0500719264ed07ca323f740645ebead9e (patch)
treee6f26bfa08bb51cca5b17c07c11163dcb3565a04
parent27f1c69a0533160dbe66690f337a45080a035246 (diff)
downloadQt-8fa348a0500719264ed07ca323f740645ebead9e.zip
Qt-8fa348a0500719264ed07ca323f740645ebead9e.tar.gz
Qt-8fa348a0500719264ed07ca323f740645ebead9e.tar.bz2
Properly escape bytearray data outside the ascii range when using a codec
Some codecs can't handle the range outside ascii properly and would then fail to read the data back in correctly. Backport of change 7df8b1ada4b23acedda5724b492c26a8e322648b from Qt 5. Task-number: QTBUG-15543 Change-Id: I4c02921e787a939eeec0c7a11603b5896d756aef Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/corelib/io/qsettings.cpp7
-rw-r--r--tests/auto/qsettings/tst_qsettings.cpp23
2 files changed, 28 insertions, 2 deletions
diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp
index bcd14a5..2f62e8f 100644
--- a/src/corelib/io/qsettings.cpp
+++ b/src/corelib/io/qsettings.cpp
@@ -680,6 +680,9 @@ void QSettingsPrivate::iniEscapedString(const QString &str, QByteArray &result,
{
bool needsQuotes = false;
bool escapeNextIfDigit = false;
+ bool useCodec = codec && !str.startsWith(QLatin1String("@ByteArray("))
+ && !str.startsWith(QLatin1String("@Variant("));
+
int i;
int startPos = result.size();
@@ -732,12 +735,12 @@ void QSettingsPrivate::iniEscapedString(const QString &str, QByteArray &result,
result += (char)ch;
break;
default:
- if (ch <= 0x1F || (ch >= 0x7F && !codec)) {
+ if (ch <= 0x1F || (ch >= 0x7F && !useCodec)) {
result += "\\x";
result += QByteArray::number(ch, 16);
escapeNextIfDigit = true;
#ifndef QT_NO_TEXTCODEC
- } else if (codec) {
+ } else if (useCodec) {
// slow
result += codec->fromUnicode(str.at(i));
#endif
diff --git a/tests/auto/qsettings/tst_qsettings.cpp b/tests/auto/qsettings/tst_qsettings.cpp
index 379d193..86e1866 100644
--- a/tests/auto/qsettings/tst_qsettings.cpp
+++ b/tests/auto/qsettings/tst_qsettings.cpp
@@ -185,6 +185,7 @@ private slots:
void testByteArray_data();
void testByteArray();
+ void iniCodec();
private:
void oldWriteEntry_data();
@@ -718,6 +719,28 @@ void tst_QSettings::testByteArray()
}
}
+void tst_QSettings::iniCodec()
+{
+ {
+ QSettings settings("QtProject", "tst_qsettings");
+ settings.setIniCodec("cp1251");
+ QByteArray ba;
+ ba.resize(256);
+ for (int i = 0; i < ba.size(); i++)
+ ba[i] = i;
+ settings.setValue("array",ba);
+ }
+ {
+ QSettings settings("QtProject", "tst_qsettings");
+ settings.setIniCodec("cp1251");
+ QByteArray ba = settings.value("array").toByteArray();
+ QCOMPARE(ba.size(), 256);
+ for (int i = 0; i < ba.size(); i++)
+ QCOMPARE((uchar)ba.at(i), (uchar)i);
+ }
+
+}
+
void tst_QSettings::testErrorHandling_data()
{
QTest::addColumn<int>("filePerms"); // -1 means file should not exist