mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-07-28 09:14:18 -04:00
Strip invalid XML chars when writing databases.
These characters are unprintable or just plain invalid. QXmlStreamReader throws and error when reading XML documents with such chars. Closes #392
This commit is contained in:
parent
5e6b17aba4
commit
2d741afe3e
4 changed files with 52 additions and 2 deletions
|
@ -374,7 +374,7 @@ void KeePass2XmlWriter::writeEntry(const Entry* entry)
|
|||
}
|
||||
|
||||
if (!value.isEmpty()) {
|
||||
m_xml.writeCharacters(value);
|
||||
m_xml.writeCharacters(stripInvalidXml10Chars(value));
|
||||
}
|
||||
m_xml.writeEndElement();
|
||||
|
||||
|
@ -445,7 +445,7 @@ void KeePass2XmlWriter::writeString(const QString& qualifiedName, const QString&
|
|||
m_xml.writeEmptyElement(qualifiedName);
|
||||
}
|
||||
else {
|
||||
m_xml.writeTextElement(qualifiedName, string);
|
||||
m_xml.writeTextElement(qualifiedName, stripInvalidXml10Chars(string));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -549,6 +549,23 @@ QString KeePass2XmlWriter::colorPartToString(int value)
|
|||
return str;
|
||||
}
|
||||
|
||||
QString KeePass2XmlWriter::stripInvalidXml10Chars(QString str)
|
||||
{
|
||||
for (int i = str.size() - 1; i >= 0; i--) {
|
||||
const ushort uc = str.at(i).unicode();
|
||||
|
||||
if ((uc < 0x20 && uc != 0x09 && uc != 0x0A && uc != 0x0D)
|
||||
|| (uc > 0xD7FF && uc < 0xE000)
|
||||
|| (uc > 0xFFFD))
|
||||
{
|
||||
qWarning("Stripping invalid XML 1.0 codepoint %x", uc);
|
||||
str.remove(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
void KeePass2XmlWriter::raiseError(const QString& errorMessage)
|
||||
{
|
||||
m_error = true;
|
||||
|
|
|
@ -73,6 +73,7 @@ private:
|
|||
void writeColor(const QString& qualifiedName, const QColor& color);
|
||||
void writeTriState(const QString& qualifiedName, Group::TriState triState);
|
||||
QString colorPartToString(int value);
|
||||
QString stripInvalidXml10Chars(QString str);
|
||||
|
||||
void raiseError(const QString& errorMessage);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue