Skip to content

Commit

Permalink
Merge pull request #1586 from xiaoyifang/fix/regex-inverted-greedy
Browse files Browse the repository at this point in the history
fix: stardict regex invertedgreedy match
  • Loading branch information
xiaoyifang authored Jun 15, 2024
2 parents 4ac44e9 + 6f6391e commit f0c55e2
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/dict/stardict.cc
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,9 @@ string StardictDictionary::handleResource( char type, char const * resource, siz
QString articleText = QString( "<div class=\"sdct_h\">" ) + QString::fromUtf8( resource, size ) + "</div>";

QRegularExpression imgRe( R"((<\s*(?:img|script)\s+[^>]*src\s*=\s*["']?)(?!(?:data|https?|ftp):))",
QRegularExpression::CaseInsensitiveOption
| QRegularExpression::InvertedGreedinessOption );
QRegularExpression::CaseInsensitiveOption );
QRegularExpression linkRe( R"((<\s*link\s+[^>]*href\s*=\s*["']?)(?!(?:data|https?|ftp):))",
QRegularExpression::CaseInsensitiveOption
| QRegularExpression::InvertedGreedinessOption );
QRegularExpression::CaseInsensitiveOption );

articleText.replace( imgRe, "\\1bres://" + QString::fromStdString( getId() ) + "/" )
.replace( linkRe, "\\1bres://" + QString::fromStdString( getId() ) + "/" );
Expand Down Expand Up @@ -517,8 +515,7 @@ string StardictDictionary::handleResource( char type, char const * resource, siz

QRegularExpression audioRe( R"(<\s*audio\s*src\s*=\s*(["']+)([^"']+)(["'])\s*>(.*)</audio>)",
QRegularExpression::CaseInsensitiveOption
| QRegularExpression::DotMatchesEverythingOption
| QRegularExpression::InvertedGreedinessOption );
| QRegularExpression::DotMatchesEverythingOption );


pos = 0;
Expand Down

0 comments on commit f0c55e2

Please sign in to comment.