Escape xml characters in composer template string replacement

This commit is contained in:
Marco Hugentobler 2012-09-28 12:11:21 +02:00
parent 3c5cb06dec
commit 3a1c9efb44
2 changed files with 17 additions and 4 deletions

View File

@ -377,7 +377,7 @@ bool QgsComposition::loadFromTemplate( const QDomDocument& doc, QMap<QString, QS
QMap<QString, QString>::const_iterator sIt = substitutionMap->constBegin(); QMap<QString, QString>::const_iterator sIt = substitutionMap->constBegin();
for ( ; sIt != substitutionMap->constEnd(); ++sIt ) for ( ; sIt != substitutionMap->constEnd(); ++sIt )
{ {
xmlString = xmlString.replace( "[" + sIt.key() + "]", sIt.value() ); xmlString = xmlString.replace( "[" + sIt.key() + "]", encodeStringForXML( sIt.value() ) );
} }
importDoc.setContent( xmlString ); importDoc.setContent( xmlString );
} }
@ -1570,3 +1570,14 @@ void QgsComposition::renderPage( QPainter* p, int page )
mPlotStyle = savedPlotStyle; mPlotStyle = savedPlotStyle;
} }
QString QgsComposition::encodeStringForXML( const QString& str )
{
QString modifiedStr( str );
modifiedStr.replace( "&", "&amp;" );
modifiedStr.replace( "\"", "&quot;" );
modifiedStr.replace( "'", "&apos;" );
modifiedStr.replace( "<", "&lt;" );
modifiedStr.replace( ">", "&gt;" );
return modifiedStr;
}

View File

@ -343,6 +343,8 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
void removePaperItems(); void removePaperItems();
void deleteAndRemoveMultiFrames(); void deleteAndRemoveMultiFrames();
static QString encodeStringForXML( const QString& str );
signals: signals:
void paperSizeChanged(); void paperSizeChanged();
void nPagesChanged(); void nPagesChanged();