Skip to content
This repository has been archived by the owner on May 12, 2020. It is now read-only.

Commit

Permalink
Ignore ping requests for now
Browse files Browse the repository at this point in the history
  • Loading branch information
bbondy committed Oct 25, 2016
1 parent 6a24133 commit afc4d2c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ void Filter::parseOption(const char *input, int len) {
*pFilterOption = static_cast<FilterOption>(*pFilterOption | FOElemHide);
} else if (!strncmp(pStart, "third-party", len)) {
*pFilterOption = static_cast<FilterOption>(*pFilterOption | FOThirdParty);
} else if (!strncmp(pStart, "ping", len)) {
*pFilterOption = static_cast<FilterOption>(*pFilterOption | FOPing);
}
// Otherwise just ignore the option, maybe something new we don't support yet
}
Expand Down Expand Up @@ -323,6 +325,9 @@ bool isThirdPartyHost(const char *baseContextHost, int baseContextHostLen,
// which are considered.
bool Filter::matchesOptions(const char *input, FilterOption context,
const char *contextDomain, const char *inputHost, int inputHostLen) {
if ((filterOption & FOUnsupported) != 0) {
return false;
}
// Maybe the user of the library can't determine a context because they're
// blocking a the HTTP level, don't block here because we don't have enough
// information
Expand Down
4 changes: 3 additions & 1 deletion filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ enum FilterOption {
FOElemHide = 010000,
FOThirdParty = 020000, // Used internally only, do not use
FONotThirdParty = 040000, // Used internally only, do not use
FOPing = 100000, // Not supported, but we will ignore these rules
FOResourcesOnly = FOScript|FOImage|FOStylesheet|FOObject|FOXmlHttpRequest|
FOObjectSubrequest|FOSubdocument|FODocument|FOOther|FOXBL
FOObjectSubrequest|FOSubdocument|FODocument|FOOther|FOXBL,
FOUnsupported = FOPing
};

class Filter {
Expand Down
6 changes: 6 additions & 0 deletions test/options-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ TEST(options, optionsFromFilter) {
{},
{}))

CHECK(testFilterOptions("https:$ping",
static_cast<FilterOption>(FOPing),
FONoFilterOption,
{},
{}))

CHECK(testFilterOptions(
"||tst.net^$object-subrequest,third-party,domain=domain1.com|domain5.com",
static_cast<FilterOption>(FOObjectSubrequest | FOThirdParty),
Expand Down
6 changes: 6 additions & 0 deletions test/parser-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,12 @@ TEST(parser, optionRules) {
OptionRuleData("http://example.com.au", FOScript, "example.com", false),
}));

// Make sure we ignore ping requests for now
CHECK(checkOptionRule("||example.com^$ping",
{
OptionRuleData("http://example.com", FOPing, "example.com", false),
}));

CHECK(checkOptionRule("||example.com^$third-party,~script",
{
OptionRuleData("http://example.com",
Expand Down

0 comments on commit afc4d2c

Please sign in to comment.