Skip to content

Commit

Permalink
AG-35300 Improve 'set-local-storage-item' — add 'allowed' and 'denied…
Browse files Browse the repository at this point in the history
…' to supported values. #445

Squashed commit of the following:

commit f2c7d96
Merge: bb1f0ce 660df28
Author: jellizaveta <e.egorova@adguard.com>
Date:   Thu Aug 22 11:10:29 2024 +0300

    Merge branch 'master' into fix/AG-35300

commit bb1f0ce
Merge: 5c2f629 48ba492
Author: jellizaveta <e.egorova@adguard.com>
Date:   Wed Aug 21 21:08:15 2024 +0300

    merge master

commit 5c2f629
Author: jellizaveta <e.egorova@adguard.com>
Date:   Wed Aug 21 19:46:42 2024 +0300

    AG-35300 Improve 'set-local-storage-item' — add 'allowed' and 'denied' to supported values. #445
  • Loading branch information
jellizaveta committed Aug 22, 2024
1 parent 660df28 commit 1e089cd
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic
- support for matching line number in `abort-on-stack-trace` scriptlet
when `inlineScript` or `injectedScript` option is used [#439]
- new values to `set-cookie` and `set-cookie-reload` scriptlets: `checked`, `unchecked` [#444]
- new values to `set-local-storage-item` and `set-session-storage-item` scriptlets:
`allowed`, `denied` [#445]

[Unreleased]: https://github.com/AdguardTeam/Scriptlets/compare/v1.11.16...HEAD
[#301]: https://github.com/AdguardTeam/Scriptlets/issues/301
[#439]: https://github.com/AdguardTeam/Scriptlets/issues/439
[#444]: https://github.com/AdguardTeam/Scriptlets/issues/444
[#445]: https://github.com/AdguardTeam/Scriptlets/issues/445

## [v1.11.16] - 2024-08-01

Expand Down
2 changes: 2 additions & 0 deletions src/helpers/storage-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ export const getLimitedStorageItemValue = (value: string): StorageItemValue | nu
'accepted',
'reject',
'rejected',
'allowed',
'denied',
]);

let validValue;
Expand Down
2 changes: 2 additions & 0 deletions src/scriptlets/set-local-storage-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ import {
* - `accepted`
* - `reject`
* - `rejected`
* - `allowed`
* - `denied`
* - `$remove$` — remove specific item from localStorage
*
* ### Examples
Expand Down
2 changes: 2 additions & 0 deletions src/scriptlets/set-session-storage-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ import {
* - `accepted`
* - `reject`
* - `rejected`
* - `allowed`
* - `denied`
* - `$remove$` — remove specific item from sessionStorage
*
* ### Examples
Expand Down
14 changes: 14 additions & 0 deletions tests/scriptlets/set-local-storage-item.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@ if (isSafariBrowser()) {
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(window.localStorage.getItem(iName), 'rejected', 'localStorage item has been set');
clearStorageItem(iName);

iName = '__test-item_allowed';
iValue = 'allowed';
runScriptlet(name, [iName, iValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(window.localStorage.getItem(iName), 'allowed', 'localStorage item has been set');
clearStorageItem(iName);

iName = '__test-item_denied';
iValue = 'denied';
runScriptlet(name, [iName, iValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(window.localStorage.getItem(iName), 'denied', 'localStorage item has been set');
clearStorageItem(iName);
});

test('Set localStorage key with invalid value', (assert) => {
Expand Down
14 changes: 14 additions & 0 deletions tests/scriptlets/set-session-storage-item.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@ if (isSafariBrowser()) {
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(window.sessionStorage.getItem(cName), 'rejected', 'sessionStorage item has been set');
clearStorageItem(cName);

cName = '__test-item_allowed';
cValue = 'allowed';
runScriptlet(name, [cName, cValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(window.sessionStorage.getItem(cName), 'allowed', 'sessionStorage item has been set');
clearStorageItem(cName);

cName = '__test-item_denied';
cValue = 'denied';
runScriptlet(name, [cName, cValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(window.sessionStorage.getItem(cName), 'denied', 'sessionStorage item has been set');
clearStorageItem(cName);
});

test('Set sessionStorage key with invalid value', (assert) => {
Expand Down

0 comments on commit 1e089cd

Please sign in to comment.