Blacklisting can use wildcard patterns
This commit is contained in:
parent
88c2596fb0
commit
d264f40f88
|
@ -2516,6 +2516,7 @@ CACHE MANIFEST
|
|||
<iframe src="http://example.com/path" id="frame1"></iframe>
|
||||
<iframe src="http://example.org/path/to/file" id="frame2"></iframe>
|
||||
<iframe src="/frame" id="frame3"></iframe>
|
||||
<iframe src="http://example.org/foo/bar" id="frame4"></iframe>
|
||||
</body>
|
||||
</html>
|
||||
HTML
|
||||
|
@ -2541,6 +2542,7 @@ CACHE MANIFEST
|
|||
|
||||
before do
|
||||
driver.browser.url_blacklist = ["http://example.org/path/to/file",
|
||||
"http://example.*/foo/*",
|
||||
"http://example.com",
|
||||
"#{AppRunner.app_host}/script"]
|
||||
end
|
||||
|
@ -2571,6 +2573,13 @@ CACHE MANIFEST
|
|||
end
|
||||
end
|
||||
|
||||
it "should not fetch urls blocked by wildcard match" do
|
||||
visit('/')
|
||||
driver.within_frame('frame4') do
|
||||
driver.find("//body").first.text.should be_empty
|
||||
end
|
||||
end
|
||||
|
||||
it "returns a status code for blocked urls" do
|
||||
visit("/")
|
||||
driver.within_frame('frame1') do
|
||||
|
|
|
@ -74,19 +74,19 @@ void NetworkAccessManager::setUrlBlacklist(QStringList urlBlacklist) {
|
|||
|
||||
QStringListIterator iter(urlBlacklist);
|
||||
while (iter.hasNext()) {
|
||||
m_urlBlacklist << QUrl(iter.next());
|
||||
m_urlBlacklist << iter.next();
|
||||
}
|
||||
};
|
||||
|
||||
bool NetworkAccessManager::isBlacklisted(QUrl url) {
|
||||
QListIterator<QUrl> iter(m_urlBlacklist);
|
||||
QString urlString = url.toString();
|
||||
QStringListIterator iter(m_urlBlacklist);
|
||||
|
||||
while (iter.hasNext()) {
|
||||
QUrl blacklisted = iter.next();
|
||||
QRegExp blacklisted = QRegExp(iter.next());
|
||||
blacklisted.setPatternSyntax(QRegExp::Wildcard);
|
||||
|
||||
if (blacklisted == url) {
|
||||
return true;
|
||||
} else if (blacklisted.path().isEmpty() && blacklisted.isParentOf(url)) {
|
||||
if(urlString.contains(blacklisted)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class NetworkAccessManager : public QNetworkAccessManager {
|
|||
QNetworkReply* createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice * outgoingData);
|
||||
QString m_userName;
|
||||
QString m_password;
|
||||
QList<QUrl> m_urlBlacklist;
|
||||
QStringList m_urlBlacklist;
|
||||
|
||||
private:
|
||||
void disableKeyChainLookup();
|
||||
|
|
Loading…
Reference in New Issue