From 76d547795ba77e239c62168f03c390b357d45e07 Mon Sep 17 00:00:00 2001 From: ShaopengLin Date: Mon, 15 Jul 2024 01:09:14 -0400 Subject: [PATCH] Sanitizes file name suggestion Convert reserved chars in the zim to '_' before it is parsed. --- src/webview.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/webview.cpp b/src/webview.cpp index 094a878fd..b6c1fe700 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -15,6 +15,12 @@ class QMenu; #include #include +#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. @@ -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