From 92e2708faef33dba35af0f52d8524af27a808280 Mon Sep 17 00:00:00 2001 From: xiaoyifang Date: Sun, 3 Apr 2022 19:39:58 +0800 Subject: [PATCH] fix: zim dictionary has improper link caused the application not function well. https://github.com/goldendict/goldendict/issues/1472#issuecomment-1086776611 --- zim.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/zim.cc b/zim.cc index e8c07b7c..2c8fabe6 100644 --- a/zim.cc +++ b/zim.cc @@ -750,7 +750,8 @@ string ZimDictionary::convert( const string & in ) // pattern , excluding any known protocols such as http://, mailto:, #(comment) // these links will be translated into local definitions - QRegularExpression rxLink( "<\\s*a\\s+([^>]*)href=\"(?!(?:\\w+://|#|mailto:|tel:))(/|)([^\"]*)\"\\s*(title=\"[^\"]*\")?[^>]*>" ); + // + QRegularExpression rxLink( "<\\s*(?:a|meta)\\s+([^>]*)(?:href|url)=\"?(?!(?:\\w+://|#|mailto:|tel:))(/|)([^\"]*)\"\\s*(title=\"[^\"]*\")?[^>]*>" ); QRegularExpressionMatchIterator it = rxLink.globalMatch( text ); int pos = 0; QString newText; @@ -763,7 +764,7 @@ string ZimDictionary::convert( const string & in ) QStringList list = match.capturedTexts(); // Add empty strings for compatibility with QRegExp behaviour - for( int i = match.lastCapturedIndex() + 1; i < 5; i++ ) + for( int i = list.size(); i < 5; i++ ) list.append( QString() ); QString tag = list[3]; // a url, ex: Precambrian_Chaotian.html @@ -832,7 +833,7 @@ string ZimDictionary::convert( const string & in ) QRegularExpressionMatchIterator it2 = rxLink.globalMatch( text ); while( it2.hasNext() ) { - QRegularExpressionMatch match = it.next(); + QRegularExpressionMatch match = it2.next(); newText += text.mid( pos, match.capturedStart() - pos ); pos = match.capturedEnd();