Fix detection of already present comment

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1281

Related feedback:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1281#issuecomment-705081202
This commit is contained in:
Raymond Hill 2020-10-07 14:23:57 -04:00
parent d84bfd3f35
commit 4f00c08f6b
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 10 additions and 6 deletions

View File

@ -416,8 +416,13 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
// The comment, if any, will be applied if and only if it is different
// from the last comment found in the user filter list.
if ( comment !== '' ) {
const pos = details.content.lastIndexOf(comment);
if ( pos === -1 || details.content.indexOf('\n!', pos + 1) !== -1 ) {
const beg = details.content.lastIndexOf(comment);
const end = beg === -1 ? -1 : beg + comment.length;
if (
end === -1 ||
details.content.startsWith('\n', end) === false ||
details.content.includes('\n!', end)
) {
filters = '\n' + comment + '\n' + filters;
}
}
@ -428,10 +433,9 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
// duplicates at this point may lead to more issues.
await this.saveUserFilters(details.content.trim() + '\n' + filters);
const compiledFilters = this.compileFilters(
filters,
{ assetKey: this.userFiltersPath }
);
const compiledFilters = this.compileFilters(filters, {
assetKey: this.userFiltersPath
});
const snfe = this.staticNetFilteringEngine;
const cfe = this.cosmeticFilteringEngine;
const acceptedCount = snfe.acceptedCount + cfe.acceptedCount;