Skip to content

Commit

Permalink
fix value validation for redirect and replace modifiers. AG-24028
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 704b3a3
Author: Slava Leleka <[email protected]>
Date:   Wed Aug 30 12:37:36 2023 +0300

    update changelog date

commit 0301ad2
Author: Slava Leleka <[email protected]>
Date:   Tue Aug 29 18:03:00 2023 +0300

    add tests

commit 388dfc8
Author: Slava Leleka <[email protected]>
Date:   Tue Aug 29 18:02:54 2023 +0300

    update changelog

commit 776112f
Author: Slava Leleka <[email protected]>
Date:   Tue Aug 29 18:02:34 2023 +0300

    fix validation result error message for regexp value_format invalid values

commit a036fe5
Author: Slava Leleka <[email protected]>
Date:   Tue Aug 29 18:01:17 2023 +0300

    fix value_format for replace

commit fc10abc
Author: Slava Leleka <[email protected]>
Date:   Tue Aug 29 18:01:05 2023 +0300

    fix value_format for redirect

commit 6e32e7f
Author: Slava Leleka <[email protected]>
Date:   Tue Aug 29 17:18:58 2023 +0300

    Revert "update changelog"

    This reverts commit f41f724.

commit f41f724
Author: Slava Leleka <[email protected]>
Date:   Tue Aug 29 17:18:25 2023 +0300

    update changelog
  • Loading branch information
slavaleleka committed Aug 30, 2023
1 parent 91625fe commit 79143ce
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
7 changes: 7 additions & 0 deletions packages/agtree/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog][keepachangelog], and this project adheres to [Semantic Versioning][semver].

## 1.1.4 - 2023-08-30

### Fixed

- Validation of `$redirect` and `$replace` modifiers by `ModifierValidator.validate()`


## 1.1.3 - 2023-08-28

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ adg_os_any:
gemius|
google-analytics-ga|
google-analytics|
googletagmanager-gtm|
google-ima3|
googlesyndication-adsbygoogle|
googletagservices-gpt|
Expand Down Expand Up @@ -90,6 +91,7 @@ adg_ext_any:
gemius|
google-analytics-ga|
google-analytics|
googletagmanager-gtm|
google-ima3|
googlesyndication-adsbygoogle|
googletagservices-gpt|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ adg_os_any:
# separator
\/
# replacement
(.+?)
(.+)?
\/
# flags
([gimuy]*)?
Expand Down Expand Up @@ -65,7 +65,7 @@ adg_ext_firefox:
# separator
\/
# replacement
(.+?)
(.+)?
\/
# flags
([gimuy]*)?
Expand Down
5 changes: 2 additions & 3 deletions packages/agtree/src/validator/value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,9 @@ export const validateValue = (modifier: Modifier, valueFormat: string): Validati
}

const modifierName = modifier.modifier.value;
const defaultInvalidValueResult = getValueRequiredValidationResult(modifierName);

if (!modifier.value?.value) {
return defaultInvalidValueResult;
return getValueRequiredValidationResult(modifierName);
}

let xRegExp;
Expand All @@ -406,7 +405,7 @@ export const validateValue = (modifier: Modifier, valueFormat: string): Validati

const isValid = xRegExp.test(modifier.value?.value);
if (!isValid) {
return defaultInvalidValueResult;
return getInvalidValidationResult(`${VALIDATION_ERROR_PREFIX.VALUE_INVALID}: '${modifierName}'`);
}

return { valid: true };
Expand Down
3 changes: 3 additions & 0 deletions packages/agtree/test/validator/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ describe('ModifierValidator', () => {
'permissions=storage-access=()\\, camera=()',
'redirect=noopjs',
'redirect=noopmp4-1s',
'redirect=googletagmanager-gtm',
'redirect-rule=noopjs',
'redirect-rule=noopmp4-1s',
'removeheader=link',
Expand All @@ -386,6 +387,8 @@ describe('ModifierValidator', () => {
'removeparam=/^__s=[A-Za-z0-9]{6\\,}/',
'replace=/("ad":{).+"(\\}\\,"(?:log|watermark)")/\\$1\\$2/',
'replace=/(<VAST[\\s\\S]*?>)[\\s\\S]*<\\/VAST>/\\$1<\\/VAST>/',
'replace=/\\,this\\.createAdDisplayContainer\\(\\)\\,this\\.setUpIMA\\(\\)//',
'replace=/fourthColumnWrapper//',
])('%s', (rawModifier) => {
const modifier = getModifier(rawModifier);
const validationResult = modifierValidator.validate(AdblockSyntax.Adg, modifier);
Expand Down

0 comments on commit 79143ce

Please sign in to comment.