Skip to content

Commit

Permalink
Remove more <script>
Browse files Browse the repository at this point in the history
  • Loading branch information
Montel committed Sep 29, 2016
1 parent a874479 commit 7797658
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Expand Up @@ -39,6 +39,9 @@ void WebEnginePartHtmlWriterTest::removeScriptInHtml_data()
QTest::newRow("onescript") << QStringLiteral("<a>boo<script>alert(1)</script></a>") << QStringLiteral("<a>boo</a>");
QTest::newRow("onescriptwithattribute") << QStringLiteral("<a>boo<script type=\"foo\">alert(1)</script></a>") << QStringLiteral("<a>boo</a>");
QTest::newRow("severalscriptwithattribute") << QStringLiteral("<p>foo</p><script>a</script><a>boo<script type=\"foo\">alert(1)</script></a>") << QStringLiteral("<p>foo</p><a>boo</a>");
//Need to fix it/.QTest::newRow("multiline") << QStringLiteral("<script>\nalert(1)</script>") << QString();
QTest::newRow("scriptwithspace") << QStringLiteral("<a>boo<script type=\"foo\" >alert(1)</script ></a>") << QStringLiteral("<a>boo</a>");
QTest::newRow("scriptwithremoveaccess") << QStringLiteral("<a>boo<script src=\"http://foo\"/></a>") << QStringLiteral("<a>boo</a>");
QTest::newRow("empty") << QString() << QString();
}

Expand Down
9 changes: 7 additions & 2 deletions messageviewer/src/htmlwriter/webengineparthtmlwriter.cpp
Expand Up @@ -74,8 +74,13 @@ void WebEnginePartHtmlWriter::end()

QString WebEnginePartHtmlWriter::removeJscripts(QString str)
{
const QRegularExpression reg(QStringLiteral("<script[^>]*>.*?</script>"));
return str.remove(reg);
//Remove regular <script>...</script>
const QRegularExpression regScript(QStringLiteral("<script[^>]*>.*?</script\\s*>"));
str = str.remove(regScript);
//Remove string as <script src=http://.../>
const QRegularExpression regScript2(QStringLiteral("<script[^>]*/>"));
str = str.remove(regScript2);
return str;
}

void WebEnginePartHtmlWriter::reset()
Expand Down

0 comments on commit 7797658

Please sign in to comment.