export: escape ' by %27 in data URI

This commit is contained in:
Le Tan 2018-07-03 19:35:17 +08:00
parent b88694bf3a
commit 7305706294
2 changed files with 5 additions and 0 deletions

View File

@ -926,6 +926,7 @@ QString VWebUtils::copyResource(const QUrl &p_url, const QString &p_folder) cons
return succ ? targetFile : QString(); return succ ? targetFile : QString();
} }
// Please use single quote to quote the URI.
QString VWebUtils::dataURI(const QUrl &p_url, bool p_keepTitle) const QString VWebUtils::dataURI(const QUrl &p_url, bool p_keepTitle) const
{ {
QString uri; QString uri;
@ -961,6 +962,9 @@ QString VWebUtils::dataURI(const QUrl &p_url, bool p_keepTitle) const
// will be removed in M68, around July 2018. Please use '%23' instead. // will be removed in M68, around July 2018. Please use '%23' instead.
uri.replace("#", "%23"); uri.replace("#", "%23");
// Escape "'" to avoid conflict with src='...' attribute.
uri.replace("'", "%27");
if (!p_keepTitle) { if (!p_keepTitle) {
// Remove <title>...</title>. // Remove <title>...</title>.
QRegExp reg("<title>.*</title>", Qt::CaseInsensitive); QRegExp reg("<title>.*</title>", Qt::CaseInsensitive);

View File

@ -26,6 +26,7 @@ public:
QString copyResource(const QUrl &p_url, const QString &p_folder) const; QString copyResource(const QUrl &p_url, const QString &p_folder) const;
// Return a dataURI of @p_url if it is an image. // Return a dataURI of @p_url if it is an image.
// Please use single quote to quote the URI.
QString dataURI(const QUrl &p_url, bool p_keepTitle = true) const; QString dataURI(const QUrl &p_url, bool p_keepTitle = true) const;
private: private: