From 9330c89e4b0f39328e4b5fc2c0ee63fcfeeb249b Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Sat, 29 Oct 2022 10:05:26 +0300 Subject: [PATCH] Don't attempt to translate empty or whitespace-only text Silently ignore empty or whitespace-only translation requests. It should be clear to most users why GoldenDict ignores them. The translated word ends up as the "word" URL query item value, which is trimmed in ArticleNetworkAccessManager::getResource(). So the added trimming in MainWindow::translateInputFinished() should be fine. When a trimmed translated word was empty, InputPhrase::isValid() returned false, ArticleNetworkAccessManager::getResource() returned a null pointer and ArticleNetworkAccessManager::createRequest() fell back to QNetworkAccessManager::createRequest(), which: * failed silently in the Qt 4 version; * displayed the Protocol "gdlookup" is unknown Failed to load URL gdlookup://localhost?word= &group=4. QtNetwork Error 301 error page in the Qt 5 version. Fixes #1179. --- mainwindow.cc | 5 ++++- scanpopup.cc | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/mainwindow.cc b/mainwindow.cc index fdea2925..680a6466 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -2343,7 +2343,10 @@ void MainWindow::updateSuggestionList( QString const & newValue ) void MainWindow::translateInputFinished( bool checkModifiers ) { - QString word = Folding::unescapeWildcardSymbols( translateLine->text() ); + QString word = translateLine->text().trimmed(); + if( word.isEmpty() ) + return; + word = Folding::unescapeWildcardSymbols( word ); respondToTranslationRequest( Config::InputPhrase( word, translateBoxSuffix ), checkModifiers ); } diff --git a/scanpopup.cc b/scanpopup.cc index 4de1ca95..764c5eb3 100644 --- a/scanpopup.cc +++ b/scanpopup.cc @@ -805,7 +805,10 @@ void ScanPopup::updateSuggestionList( QString const & text ) void ScanPopup::translateInputFinished() { - inputPhrase.phrase = Folding::unescapeWildcardSymbols( ui.translateBox->translateLine()->text().trimmed() ); + QString const word = ui.translateBox->translateLine()->text().trimmed(); + if( word.isEmpty() ) + return; + inputPhrase.phrase = Folding::unescapeWildcardSymbols( word ); inputPhrase.punctuationSuffix = translateBoxSuffix; showTranslationFor( inputPhrase ); }