Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdded option to preserve original filter text #98
Conversation
| @@ -294,6 +304,13 @@ void parseFilter(const char *input, const char *end, Filter *f, | |||
| f->data = new char[len]; | |||
| f->data[len - 1] = '\0'; | |||
| memcpy(f->data, input + i + 1, len - 1); | |||
|
|
|||
| if (preserveRules == true) { | |||
This comment has been minimized.
This comment has been minimized.
| @@ -781,6 +798,15 @@ uint32_t Filter::serialize(char *buffer) { | |||
| } | |||
| totalSize += 1; | |||
|
|
|||
| if (ruleDefinition) { | |||
This comment has been minimized.
This comment has been minimized.
bbondy
May 14, 2018
Member
I don't think this is serializing correctly, I think we would need to store the ruleDefinitionSize in the above snprintf
This comment has been minimized.
This comment has been minimized.
bbondy
May 14, 2018
Member
Pls also add a test to test/js/serializationTest.js for that to ensure it works.
| @@ -826,6 +852,14 @@ uint32_t Filter::deserialize(char *buffer, uint32_t bufferSize) { | |||
| } | |||
| consumed += hostLen + 1; | |||
|
|
|||
| uint32_t ruleDefinitionLen = static_cast<uint32_t>(strlen(buffer + consumed)); | |||
This comment has been minimized.
This comment has been minimized.
| FilterParseState parseState = FPStart; | ||
| const char *p = input; | ||
| const char *q = p; |
This comment has been minimized.
This comment has been minimized.
| char data[kMaxLineLength]; | ||
| memset(data, 0, sizeof data); | ||
| int i = 0; | ||
|
|
||
| int ruleTextLength = 0; |
This comment has been minimized.
This comment has been minimized.
bbondy
May 14, 2018
Member
I think we can just subtract filterRuleEndPos from the line start pos to get the same length. So we can probably get rid of this.
73a1094
to
1dcc7ce
|
@bbondy rebased and change to address your comments. I also added a couple new sets of tests. One thing that came up when writing this up though: i don't see anywhere that the Unless I'm missing where these methods are used, would you mind if I deleted all four methods, to avoid future possible confusion? |
| @@ -347,9 +365,12 @@ void parseFilter(const char *input, const char *end, Filter *f, | |||
| } | |||
| parseState = FPDataOnly; | |||
| f->filterType = FTHTMLFiltering; | |||
| p+=2; | |||
| p += 2; | |||
This comment has been minimized.
This comment has been minimized.
| if (buffer) { | ||
| snprintf(buffer + bufferSize, bufferSizeAvail, "%s", f->ruleDefinition); | ||
| } | ||
| bufferSize += static_cast<int>(strlen(f->ruleDefinition)); |
This comment has been minimized.
This comment has been minimized.
bbondy
Jul 16, 2018
Member
any time serialization deserialization is changed, we need to update the adblock version, so I'm ok with this but you'd have to set it to version 5.
| size_t len = strlen(other.ruleDefinition) + 1; | ||
| ruleDefinition = new char[len]; | ||
| snprintf(ruleDefinition, len, "%s", other.ruleDefinition); | ||
| ruleDefinitionLen = len - 1; |
This comment has been minimized.
This comment has been minimized.
bbondy
Jul 16, 2018
Member
this is different from above, before the len included the 0 terminated character.
4a238ff
to
861ba9e
…ign of adguard filters, linter corrections
861ba9e
to
b84c6d7
pes10k commentedApr 15, 2018
added a bool flag to
AdBlockClient.prototype.parseto control whether this data should be preserved (since otherwise the text of ~ the entire filter list would be preserved in the uncommon case of wanting to usefindMatchingFilters).If
true, then the return value offindMatchingFilterswill havematchingOrigRuleandmatchingExceptionOrigRuleproperties that have the original filter rule text. Iffalse, then thematchingOrigRuleandmatchingExceptionOrigRuleproperties areundefined