Commit 717d69a6 authored by Johannes Zarl-Zierl's avatar Johannes Zarl-Zierl

Fix bugfix in commit ac5370fb

Fix regression introduced by d34534b5.
Implementing a format string conversion for "%0X" correctly and in a
backwards compatible mode has proven to be harder than I thought.
So I opted to replace the deprecated QString::sprintf() with
QString::asprintf(), which is not recommended for new code but not
deprecated either.

Note: if you ever reimplement this, check the following characters for

 " " -> "_.20"
 "%" -> "_.25"
 "&" -> "_.26"
 "ä" -> "_.FFFFFFE4"
 "ö" -> "_.FFFFFFF6"
 "ü" -> "_.FFFFFFFC"
 "⌘" -> "_.0" //note: this is incorrect behaviour
 "\uD83D" -> "_.0" //note: this is incorrect behaviour
 "\uDE03" -> "_.0" //note: this is incorrect behaviour

The incorrectly escaped characters won't be a problem immediately,
because the attribute will be correctly mapped to the right category.
This just means that all of the last three example characters will be
mapped to the same string, leading to possible ambiguities.
parent 6de35fc2
......@@ -491,11 +491,7 @@ QString XMLDB::FileWriter::escape(const QString &str)
if (useCompressedFileFormat()) {
while ((pos = rx.indexIn(tmp, pos)) != -1) {
QString before = rx.cap(1);
// the old version called QString::sprintf("_.%0X", rx.cap(1).toLatin1())
// -> by using the hex value, the string is essentially cast as a number, creating the leading 0xff bytes
// since the latin1 is always 1 byte, we should always have 3 leading 0xff bytes, i.e. 6 'F' in total:
QString after = QString::fromLatin1("_.FFFFFF");
after += QString::fromLocal8Bit(rx.cap(1).toLatin1().toHex().toUpper());
QString after = QString::asprintf("_.%0X", rx.cap(1).data()->toLatin1());
tmp.replace(pos, before.length(), after);
pos += after.length();
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment