Skip to content

Commit

Permalink
Sanitizes file name suggestion
Browse files Browse the repository at this point in the history
Convert reserved chars in the zim to '_' before it is parsed.
  • Loading branch information
ShaopengLin committed Jul 15, 2024
1 parent a474bac commit 76d5477
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/webview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ class QMenu;
#include <zim/error.h>
#include <zim/item.h>

#ifdef Q_OS_WIN
const QRegularExpression reservedCharsRe("[<>:\"/\\\\|?*]");
#else
const QRegularExpression reservedCharsRe("/");
#endif

void WebViewBackMenu::showEvent(QShowEvent *)
{
/* In Qt 5.12 CSS options for shifting this menu didn't work.
Expand Down Expand Up @@ -146,7 +152,11 @@ void WebView::saveViewContent()
auto mimeType = QByteArray::fromStdString(item.getMimetype());
mimeType = mimeType.split(';')[0];

/* We have to sanitize here, as parsing will start once we pass the file
name to either save or download method.
*/
QString suggestedFileName = item.getTitle().c_str();
suggestedFileName = suggestedFileName.replace(reservedCharsRe, "_");
if (mimeType == "text/html")
page()->save(suggestedFileName + ".pdf");
else
Expand Down

0 comments on commit 76d5477

Please sign in to comment.