Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ghostery_id optional #3372

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions packages/adblocker/src/engine/metadata/patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface IPattern {
readonly organization: string | null;
readonly alias: string | null;
readonly website_url: string | null;
readonly ghostery_id: string;
readonly ghostery_id: string | null;
readonly domains: string[];
readonly filters: string[];
}
Expand All @@ -44,7 +44,6 @@ export function isValid(pattern: any): pattern is IPattern {
organization,
alias,
website_url: websiteUrl,
ghostery_id: ghosteryId,
domains,
filters,
} = pattern;
Expand Down Expand Up @@ -73,10 +72,6 @@ export function isValid(pattern: any): pattern is IPattern {
return false;
}

if (typeof ghosteryId !== 'string') {
return false;
}

if (!Array.isArray(domains) || !domains.every((domain) => typeof domain === 'string')) {
return false;
}
Expand Down Expand Up @@ -126,7 +121,7 @@ export function getSerializedSize(pattern: IPattern): number {
sizeOfUTF8(pattern.organization || '') +
sizeOfUTF8(pattern.alias || '') +
sizeOfUTF8(pattern.website_url || '') +
sizeOfUTF8(pattern.ghostery_id) +
sizeOfUTF8(pattern.ghostery_id || '') +
sizeOfDomains +
sizeOfFilters
);
Expand All @@ -139,7 +134,7 @@ export function serialize(pattern: IPattern, view: StaticDataView) {
view.pushUTF8(pattern.organization || '');
view.pushUTF8(pattern.alias || '');
view.pushUTF8(pattern.website_url || '');
view.pushUTF8(pattern.ghostery_id);
view.pushUTF8(pattern.ghostery_id || '');

view.pushLength(pattern.domains.length);
for (const domain of pattern.domains) {
Expand All @@ -159,7 +154,7 @@ export function deserialize(view: StaticDataView): IPattern {
const organization = view.getUTF8() || null;
const alias = view.getUTF8() || null;
const website_url = view.getUTF8() || null;
const ghostery_id = view.getUTF8();
const ghostery_id = view.getUTF8() || null;

const numberOfDomains = view.getLength();
const domains = [];
Expand Down