From 8388cd8ee6f30d8a0b95a7881ecd0cd1405337ad Mon Sep 17 00:00:00 2001 From: Abs62 Date: Wed, 9 Mar 2016 23:06:53 +0300 Subject: [PATCH] MDict: Fix some scripts handling --- mdx.cc | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/mdx.cc b/mdx.cc index 27c1649c..d16a5881 100644 --- a/mdx.cc +++ b/mdx.cc @@ -965,9 +965,6 @@ QString & MdxDictionary::filterResource( QString const & articleId, QString & ar Qt::CaseInsensitive, QRegExp::RegExp2 ), "\\1\"bres://" + id + "/\\\"" ) // javascripts - .replace( QRegExp( "(<\\s*script\\s+[^>]*\\bsrc\\b\\s*=\\s*[\"']+)(?:file://)?[\\x00-\\x30\\x7f]*([^\"']*)", - Qt::CaseInsensitive, QRegExp::RegExp2 ), - "\\1bres://" + id + "/\\2" ) .replace( QRegExp( "(<\\s*script\\s+[^>]*\\bsrc\\b\\s*=\\s*)(?!['\"]+)(?!bres:|data:)(?:file://)?([^\\s>]+)", Qt::CaseInsensitive, QRegExp::RegExp2 ), "\\1\"bres://" + id + "/\\\"" ) @@ -998,6 +995,31 @@ QString & MdxDictionary::filterResource( QString const & articleId, QString & ar pos += newLink.size(); } + // javascripts + QRegExp regScript( "(<\\s*script\\s+[^>]*\\bsrc\\b\\s*=\\s*[\"']+)(?:file://)?[\\x00-\\x30\\x7f]*([^\"']*)", + Qt::CaseInsensitive, QRegExp::RegExp2 ); + QRegExp regDynamic( "\\Wreplace(" ); + pos = 0; + while( pos >= 0 ) + { + pos = wordCrossLink.indexIn( article, pos ); + if( pos < 0 ) + break; + + if( regScript.cap( 1 ).indexOf( regDynamic ) >= 0 ) + { + pos += regScript.cap( 0 ).size(); + continue; + } + + QString newLink = regScript.cap( 1 ) + + "bres://" + id + "/" + + regScript.cap( 2 ); + + article.replace( pos, regScript.cap( 0 ).size(), newLink ); + pos += newLink.size(); + } + return article; }