Skip to content

Commit

Permalink
fix CosmeticApi.getScriptText() return type. AG-25896
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit d429f0a
Merge: f102f43 3d6c256
Author: Slava Leleka <[email protected]>
Date:   Thu Nov 30 14:04:05 2023 +0200

    Merge branch 'master' into fix/AG-25896

commit f102f43
Author: Vladimir Zhelvis <[email protected]>
Date:   Fri Nov 24 18:08:27 2023 +0300

    fix comment online with Bitbucket

commit 00b080b
Author: Slava Leleka <[email protected]>
Date:   Wed Nov 22 17:05:47 2023 +0200

    fix CosmeticApi.getScriptText() return type
  • Loading branch information
slavaleleka committed Nov 30, 2023
1 parent 3d6c256 commit 01a9240
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 4 additions & 7 deletions packages/tswebextension/src/lib/mv2/background/cosmetic-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ export class CosmeticApi extends CosmeticApiCommon {
*
* @param rules Cosmetic rules.
* @param frameUrl Frame url.
* @returns Scripts or undefined.
* @returns Script text or empty string if no script rules are passed.
*/
public static getScriptText(rules: CosmeticRule[], frameUrl?: string): string | undefined {
public static getScriptText(rules: CosmeticRule[], frameUrl?: string): string {
if (rules.length === 0) {
return undefined;
return '';
}

const permittedRules = CosmeticApi.sanitizeScriptRules(rules);
Expand All @@ -191,7 +191,7 @@ export class CosmeticApi extends CosmeticApiCommon {
.join('\n');

if (!scriptText) {
return undefined;
return '';
}

return `
Expand Down Expand Up @@ -292,9 +292,6 @@ export class CosmeticApi extends CosmeticApiCommon {
const scriptRules = cosmeticResult.getScriptRules();

let scriptText = CosmeticApi.getScriptText(scriptRules, url);
// TODO: fix concatenation of undefined and string because:
// undefined + '<stealth script>' === 'undefined<stealth script>'
// AG-25896.
scriptText += stealthApi.getSetDomSignalScript();

if (scriptText) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,14 @@ describe('cosmetic api', () => {
expect(scriptText?.replace(/\s/g, '')).toStrictEqual(expectScriptText.replace(/\s/g, ''));
});

it('no rules -- empty string', () => {
const testRules: CosmeticRule[] = [];

const scriptText = CosmeticApi.getScriptText(testRules);

expect(scriptText).toStrictEqual('');
});

it('allow scriptlets and JS rules from custom filter in all browsers, except FirefoxAMO', () => {
const CUSTOM_FILTER_ID = 1001;

Expand Down

0 comments on commit 01a9240

Please sign in to comment.