From aa9ed9bc38e288dbced2b86c010b5da969b88906 Mon Sep 17 00:00:00 2001 From: xiaoyifang Date: Tue, 22 Nov 2022 18:03:59 +0800 Subject: [PATCH 1/6] fix:zim regression image can not displayed --- zim.cc | 53 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/zim.cc b/zim.cc index f352383d..04a5df12 100644 --- a/zim.cc +++ b/zim.cc @@ -128,7 +128,7 @@ __attribute__((packed)) enum { Signature = 0x584D495A, // ZIMX on little-endian, XMIZ on big-endian - CurrentFormatVersion = 3 + BtreeIndexing::FormatVersion + Folding::Version + CurrentFormatVersion = 4 + BtreeIndexing::FormatVersion + Folding::Version }; struct IdxHeader @@ -839,8 +839,44 @@ string ZimDictionary::convert( const string & in ) QString( "]*)src=(\"|)(\\.\\./)*" ), - QString( "<\\1 \\2src=\\3bres://%1/").arg( getId().c_str() ) ); + // text.replace( QRegularExpression( "<\\s*(img|script)\\s+([^>]*)src=(\")([^\"]*)\\3" ), + // QString( "<\\1 \\2src=\\3bres://%1/").arg( getId().c_str() ) ); + + QRegularExpression rxImgScript( "<\\s*(img|script)\\s+([^>]*)src=(\")([^\"]*)\\3" ); + QRegularExpressionMatchIterator it = rxImgScript.globalMatch( text ); + int pos = 0; + QString newText; + while( it.hasNext() ) + { + QRegularExpressionMatch match = it.next(); + + newText += text.mid( pos, match.capturedStart() - pos ); + pos = match.capturedEnd(); + + QStringList list = match.capturedTexts(); + + QString url = list[ 4 ]; // a url + + QString urlLink = match.captured(); + + QString replacedLink = urlLink; + if( !url.isEmpty() && !url.startsWith( "//" ) && !url.startsWith( "http://" ) && !url.startsWith( "https://" ) ) + { + //<\\1 \\2src=\\3bres://%1/ + url.replace( RX::Zim::linkSpecialChar, "" ); + replacedLink = + QString( "<%1 %2 src=\"bres://%3/%4\"" ).arg( list[ 1 ], list[ 2 ], QString::fromStdString( getId() ), url ); + } + + newText += replacedLink; + } + if( pos ) + { + newText += text.mid( pos ); + text = newText; + } + newText.clear(); + // Fix links without '"' text.replace( QRegularExpression( "href=(\\.\\.|)/([^\\s>]+)" ), @@ -860,9 +896,8 @@ string ZimDictionary::convert( const string & in ) // these links will be translated into local definitions // QRegularExpression rxLink( "<\\s*(?:a|meta)\\s+([^>]*)(?:href|url)=\"?(?!(?:\\w+://|#|mailto:|tel:))()([^\"]*)\"\\s*(title=\"[^\"]*\")?[^>]*>" ); - QRegularExpressionMatchIterator it = rxLink.globalMatch( text ); - int pos = 0; - QString newText; + it = rxLink.globalMatch( text ); + pos = 0; while( it.hasNext() ) { QRegularExpressionMatch match = it.next(); @@ -1658,6 +1693,8 @@ vector< sptr< Dictionary::Class > > makeDictionaries( } else { + url.insert( url.begin(), '/' ); + url.insert( url.begin(), nameSpace ); auto formatedUrl = QString::fromStdString(url).replace(RX::Zim::linkSpecialChar,""); indexedResources.addSingleWord( Utf8::decode( formatedUrl.toStdString() ), n ); } @@ -1695,8 +1732,8 @@ vector< sptr< Dictionary::Class > > makeDictionaries( } else { -// url.insert( url.begin(), '/' ); -// url.insert( url.begin(), nameSpace ); + url.insert( url.begin(), '/' ); + url.insert( url.begin(), nameSpace ); auto formatedUrl = QString::fromStdString(url).replace(RX::Zim::linkSpecialChar,""); indexedResources.addSingleWord( Utf8::decode( formatedUrl.toStdString() ), n ); } From f3975837c48284fdd21ac9d44c59af73d5ebd2fc Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Wed, 23 Nov 2022 20:40:19 +0800 Subject: [PATCH 2/6] fix: fix zim resource namespace remove possible namespace from the article,the namespace should follow the following pattern '/J/resoucename.js' etc --- zim.cc | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/zim.cc b/zim.cc index 04a5df12..1b1c94f4 100644 --- a/zim.cc +++ b/zim.cc @@ -863,7 +863,7 @@ string ZimDictionary::convert( const string & in ) if( !url.isEmpty() && !url.startsWith( "//" ) && !url.startsWith( "http://" ) && !url.startsWith( "https://" ) ) { //<\\1 \\2src=\\3bres://%1/ - url.replace( RX::Zim::linkSpecialChar, "" ); + url.remove(QRegularExpression("^\\.*\\/[A-Z]\\/", QRegularExpression::CaseInsensitiveOption)); replacedLink = QString( "<%1 %2 src=\"bres://%3/%4\"" ).arg( list[ 1 ], list[ 2 ], QString::fromStdString( getId() ), url ); } @@ -1520,8 +1520,8 @@ void ZimResourceRequest::run() sptr< Dictionary::DataRequest > ZimDictionary::getResource( string const & name ) { - auto formatedName = QString::fromStdString(name).replace(RX::Zim::linkSpecialChar,""); - return new ZimResourceRequest( *this, formatedName.toStdString() ); +// auto formatedName = QString::fromStdString(name).replace(RX::Zim::linkSpecialChar,""); + return new ZimResourceRequest( *this, name ); } //} // anonymous namespace @@ -1693,10 +1693,10 @@ vector< sptr< Dictionary::Class > > makeDictionaries( } else { - url.insert( url.begin(), '/' ); - url.insert( url.begin(), nameSpace ); - auto formatedUrl = QString::fromStdString(url).replace(RX::Zim::linkSpecialChar,""); - indexedResources.addSingleWord( Utf8::decode( formatedUrl.toStdString() ), n ); +// url.insert( url.begin(), '/' ); +// url.insert( url.begin(), nameSpace ); +// auto formatedUrl = QString::fromStdString(url).replace(RX::Zim::linkSpecialChar," "); + indexedResources.addSingleWord( Utf8::decode( url ), n ); } } else @@ -1726,16 +1726,14 @@ vector< sptr< Dictionary::Class > > makeDictionaries( } } else - if( nameSpace == 'X' ) + if( nameSpace == 'X' || nameSpace=='V' || nameSpace=='U'|| nameSpace=='W' ) { continue; } else { - url.insert( url.begin(), '/' ); - url.insert( url.begin(), nameSpace ); - auto formatedUrl = QString::fromStdString(url).replace(RX::Zim::linkSpecialChar,""); - indexedResources.addSingleWord( Utf8::decode( formatedUrl.toStdString() ), n ); +// auto formatedUrl = QString::fromStdString(url).replace(RX::Zim::linkSpecialChar," "); + indexedResources.addSingleWord( Utf8::decode( url ), n ); } } From c2607dbb319ca63eb1e1b3170a2e93d7801d3171 Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Thu, 24 Nov 2022 07:16:18 +0800 Subject: [PATCH 3/6] fix : zim resource link --- zim.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zim.cc b/zim.cc index 1b1c94f4..8fdbadad 100644 --- a/zim.cc +++ b/zim.cc @@ -1520,8 +1520,8 @@ void ZimResourceRequest::run() sptr< Dictionary::DataRequest > ZimDictionary::getResource( string const & name ) { -// auto formatedName = QString::fromStdString(name).replace(RX::Zim::linkSpecialChar,""); - return new ZimResourceRequest( *this, name ); + auto formatedName = QString::fromStdString(name).remove(QRegularExpression("^\\.*\\/[A-Z]\\/", QRegularExpression::CaseInsensitiveOption)); + return new ZimResourceRequest( *this, formatedName.toStdString() ); } //} // anonymous namespace From a482a2116dde0cc90df3f47486ac9b93fb567af0 Mon Sep 17 00:00:00 2001 From: xiaoyifang Date: Thu, 24 Nov 2022 16:39:01 +0800 Subject: [PATCH 4/6] [qt]remove qt6.4.1 in Windows due to bugs in qt --- .github/workflows/windows-6.x-xapian.yml | 2 +- .github/workflows/windows-6.x.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/windows-6.x-xapian.yml b/.github/workflows/windows-6.x-xapian.yml index f311b465..97d9661f 100644 --- a/.github/workflows/windows-6.x-xapian.yml +++ b/.github/workflows/windows-6.x-xapian.yml @@ -27,7 +27,7 @@ jobs: strategy: matrix: os: [windows-2019] - qt_ver: [6.3.2,6.4.1] + qt_ver: [6.3.2] qt_arch: [win64_msvc2019_64] env: targetName: GoldenDict.exe diff --git a/.github/workflows/windows-6.x.yml b/.github/workflows/windows-6.x.yml index 7350dc83..148ff24b 100644 --- a/.github/workflows/windows-6.x.yml +++ b/.github/workflows/windows-6.x.yml @@ -27,7 +27,7 @@ jobs: strategy: matrix: os: [windows-2019] - qt_ver: [6.3.2,6.4.1] + qt_ver: [6.3.2] qt_arch: [win64_msvc2019_64] env: targetName: GoldenDict.exe From 1284846d27ef6420f3807c8025a43ff164e36fc4 Mon Sep 17 00:00:00 2001 From: xiaoyifang Date: Thu, 24 Nov 2022 17:04:03 +0800 Subject: [PATCH 5/6] bump alpha version to 22.11.24 --- .github/workflows/AutoTag.yml | 2 +- .github/workflows/macos-6.x.yml | 2 +- .github/workflows/macos-homebrew.yml | 2 +- .github/workflows/macos.yml | 2 +- .github/workflows/ubuntu-6.2.yml | 2 +- .github/workflows/ubuntu.yml | 2 +- .github/workflows/windows-6.x-xapian.yml | 2 +- .github/workflows/windows-6.x.yml | 2 +- .github/workflows/windows.yml | 2 +- goldendict.pro | 4 ++-- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/AutoTag.yml b/.github/workflows/AutoTag.yml index bc5a2ef9..3f2ee4d8 100644 --- a/.github/workflows/AutoTag.yml +++ b/.github/workflows/AutoTag.yml @@ -22,7 +22,7 @@ jobs: runs-on: ubuntu-latest env: - version: 22.9.24 + version: 22.11.24 version-suffix: alpha prerelease: true diff --git a/.github/workflows/macos-6.x.yml b/.github/workflows/macos-6.x.yml index addae0c2..146b433f 100644 --- a/.github/workflows/macos-6.x.yml +++ b/.github/workflows/macos-6.x.yml @@ -29,7 +29,7 @@ jobs: qt_arch: [clang_64] env: targetName: GoldenDict - version: 22.9.24 + version: 22.11.24 version-suffix: alpha prerelease: true diff --git a/.github/workflows/macos-homebrew.yml b/.github/workflows/macos-homebrew.yml index 3c4c6b26..5bdf2103 100644 --- a/.github/workflows/macos-homebrew.yml +++ b/.github/workflows/macos-homebrew.yml @@ -26,7 +26,7 @@ jobs: qt_arch: [clang_64] env: targetName: GoldenDict - version: 22.9.24 + version: 22.11.24 version-suffix: alpha prerelease: true steps: diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 70c8eaba..1f21e05e 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -30,7 +30,7 @@ jobs: qt_arch: [clang_64] env: targetName: GoldenDict - version: 22.9.24 + version: 22.11.24 version-suffix: alpha prerelease: true diff --git a/.github/workflows/ubuntu-6.2.yml b/.github/workflows/ubuntu-6.2.yml index 8f85c9ca..d82678e3 100644 --- a/.github/workflows/ubuntu-6.2.yml +++ b/.github/workflows/ubuntu-6.2.yml @@ -30,7 +30,7 @@ jobs: qt_ver: [6.3.2,6.4.1] qt_arch: [gcc_64] env: - version: 22.9.24 + version: 22.11.24 version-suffix: alpha prerelease: true steps: diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 4db0aff6..2f5b4d8a 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -30,7 +30,7 @@ jobs: qt_ver: [5.15.2] qt_arch: [gcc_64] env: - version: 22.9.24 + version: 22.11.24 version-suffix: alpha prerelease: true steps: diff --git a/.github/workflows/windows-6.x-xapian.yml b/.github/workflows/windows-6.x-xapian.yml index 97d9661f..7736b7f9 100644 --- a/.github/workflows/windows-6.x-xapian.yml +++ b/.github/workflows/windows-6.x-xapian.yml @@ -31,7 +31,7 @@ jobs: qt_arch: [win64_msvc2019_64] env: targetName: GoldenDict.exe - version: 22.9.24 + version: 22.11.24 version-suffix: alpha prerelease: true steps: diff --git a/.github/workflows/windows-6.x.yml b/.github/workflows/windows-6.x.yml index 148ff24b..0358734a 100644 --- a/.github/workflows/windows-6.x.yml +++ b/.github/workflows/windows-6.x.yml @@ -31,7 +31,7 @@ jobs: qt_arch: [win64_msvc2019_64] env: targetName: GoldenDict.exe - version: 22.9.24 + version: 22.11.24 version-suffix: alpha prerelease: true steps: diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 9bfecbbb..c4c5deeb 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -32,7 +32,7 @@ jobs: qt_arch: [win64_msvc2019_64] env: targetName: GoldenDict.exe - version: 22.9.24 + version: 22.11.24 version-suffix: alpha prerelease: true # 步骤 diff --git a/goldendict.pro b/goldendict.pro index a55ef6a5..a7018b4f 100644 --- a/goldendict.pro +++ b/goldendict.pro @@ -1,6 +1,6 @@ TEMPLATE = app TARGET = goldendict -VERSION = 22.9.24-alpha +VERSION = 22.11.24-alpha # Generate version file. We do this here and in a build rule described later. # The build rule is required since qmake isn't run each time the project is @@ -89,7 +89,7 @@ win32 { win32-msvc* { # VS does not recognize 22.number.alpha,cause errors during compilation under MSVC++ - VERSION = 22.9.24 + VERSION = 22.11.24 DEFINES += __WIN32 _CRT_SECURE_NO_WARNINGS contains(QMAKE_TARGET.arch, x86_64) { DEFINES += NOMINMAX __WIN64 From df2bb387e2c789973dc6c367df36d308f6b3148e Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Thu, 24 Nov 2022 20:34:21 +0800 Subject: [PATCH 6/6] fix : add default groupid to the globalinstance --- article_netmgr.cc | 9 ++------- globalbroadcaster.h | 1 + mainwindow.cc | 5 +++++ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/article_netmgr.cc b/article_netmgr.cc index a91040f6..3a4e6037 100644 --- a/article_netmgr.cc +++ b/article_netmgr.cc @@ -170,14 +170,9 @@ QNetworkReply * ArticleNetworkAccessManager::getArticleReply( QNetworkRequest co if( !path.isEmpty() ) { url.setPath( "" ); - QByteArray referer = req.rawHeader( "Referer" ); - QUrl refererUrl = QUrl::fromEncoded( referer ); Utils::Url::addQueryItem( url, "word", path.mid( 1 ) ); - if( Utils::Url::hasQueryItem( refererUrl, "group" ) ) - { - Utils::Url::addQueryItem( url, "group", Utils::Url::queryItemValue( refererUrl, "group" ) ); - } + Utils::Url::addQueryItem( url, "group", QString::number(GlobalBroadcaster::instance()->currentGroupId ) ); } } @@ -318,7 +313,7 @@ sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource( bool ignoreDiacritics = Utils::Url::queryItemValue( url, "ignore_diacritics" ) == "1"; - if ( phrase.isValid() ) // Require group and phrase to be passed + if ( groupIsValid && phrase.isValid() ) // Require group and phrase to be passed return articleMaker.makeDefinitionFor( phrase, group, contexts, mutedDicts, QStringList(), ignoreDiacritics ); } diff --git a/globalbroadcaster.h b/globalbroadcaster.h index 20b44aea..83f7ff8e 100644 --- a/globalbroadcaster.h +++ b/globalbroadcaster.h @@ -25,6 +25,7 @@ public: void addWhitelist(QString host); bool existedInWhitelist(QString host); static GlobalBroadcaster * instance(); + unsigned currentGroupId; signals: void dictionaryChanges( ActiveDictIds ad ); diff --git a/mainwindow.cc b/mainwindow.cc index 82573424..9dfe5fac 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -572,6 +572,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ): igrp->checkMutedDictionaries( &grp->mutedDictionaries ); dictionaryBar.setMutedDictionaries( grp ? &grp->mutedDictionaries : 0 ); } + GlobalBroadcaster::instance()->currentGroupId = cfg.lastMainGroupId; showDictBarNamesTriggered(); // Make update its state according to initial // setting @@ -2323,6 +2324,10 @@ void MainWindow::currentGroupChanged( int ) dictionaryBar.setMutedDictionaries( 0 ); } + if(igrp){ + GlobalBroadcaster::instance()->currentGroupId = cfg.lastMainGroupId; + } + updateDictionaryBar(); // Update word search results