Skip to content

Commit

Permalink
Merge branch 'master' into feature/AG-22559
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamWr committed Jan 30, 2024
2 parents 4537c0a + 1e27fb3 commit 307fb6e
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 173 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic
### Added

- `spoof-css` scriptlet [#317](https://github.com/AdguardTeam/Scriptlets/issues/317)
- New values `t`, `f`, `necessary`, `required` for `set-cookie` and `set-cookie-reload`
[#379](https://github.com/AdguardTeam/Scriptlets/issues/379)

## [v1.9.105] - 2023-12-25

Expand Down
3 changes: 1 addition & 2 deletions bamboo-specs/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ Build:
yarn install ${bamboo.varsYarn}
yarn build
yarn wiki:build-docs
yarn wiki:build-table
yarn wiki
rm -rf node_modules
- inject-variables:
Expand Down
6 changes: 2 additions & 4 deletions bamboo-specs/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ Build:
yarn install
# build docs to lint them later
# 1. check compatibility table updates and build it
yarn wiki:build-table
# 2. build other wiki docs
yarn wiki:build-docs
# check compatibility table updates and build it and build wiki docs
yarn wiki
yarn test
yarn build
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adguard/scriptlets",
"version": "1.9.106",
"version": "1.9.107",
"description": "AdGuard's JavaScript library of Scriptlets and Redirect resources",
"scripts": {
"build": "babel-node -x .js,.ts scripts/build.js",
Expand All @@ -12,6 +12,7 @@
"lint:md": "markdownlint .",
"lint-staged": "lint-staged",
"prepare": "husky install",
"wiki": "yarn wiki:build-table && yarn wiki:build-docs",
"wiki:build-table": "node ./scripts/check-sources-updates.js && node ./scripts/build-compatibility-table.js",
"wiki:build-docs": "node scripts/build-docs.js",
"prepublishOnly": "yarn build",
Expand Down
3 changes: 3 additions & 0 deletions scripts/compatibility-table.json
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@
{
"ubo": "trusted-replace-node-text.js (trusted-rpnt.js, replace-node-text.js, rpnt.js)"
},
{
"ubo": "remove-cache-storage-item.js"
},
{
"ubo": "trusted-replace-argument.js"
}
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/cookie-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ export const getLimitedCookieValue = (value: string): string | number | null =>

const allowedCookieValues = new Set([
'true',
't',
'false',
'f',
'yes',
'y',
'no',
Expand All @@ -83,6 +85,8 @@ export const getLimitedCookieValue = (value: string): string | number | null =>
'enabled',
'disable',
'disabled',
'necessary',
'required',
]);

let validValue;
Expand Down
14 changes: 10 additions & 4 deletions src/scriptlets/set-cookie-reload.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@ import {
* - `value` — required, cookie value; possible values:
* - number `>= 0 && <= 15`
* - one of the predefined constants in any case variation:
* - `true`
* - `false`
* - `true` / `t`
* - `false` / `f`
* - `yes` / `y`
* - `no` / `n`
* - `ok`
* - `accept`/ `reject`
* - `allow` / `deny`
* - `on` / `off`
* - `accept`/ `accepted` / `notaccepted`
* - `reject` / `rejected`
* - `allow` / `allowed`
* - `disallow` / `deny`
* - `enable` / `enabled`
* - `disable` / `disabled`
* - `necessary` / `required`
* - `path` — optional, cookie path, defaults to `/`; possible values:
* - `/` — root path
* - `none` — to set no path at all
Expand Down
5 changes: 3 additions & 2 deletions src/scriptlets/set-cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import {
* - `value` — required, cookie value; possible values:
* - number `>= 0 && <= 15`
* - one of the predefined constants in any case variation:
* - `true`
* - `false`
* - `true` / `t`
* - `false` / `f`
* - `yes` / `y`
* - `no` / `n`
* - `ok`
Expand All @@ -43,6 +43,7 @@ import {
* - `disallow` / `deny`
* - `enable` / `enabled`
* - `disable` / `disabled`
* - `necessary` / `required`
* - `path` — optional, cookie path, defaults to `/`; possible values:
* - `/` — root path
* - `none` — to set no path at all
Expand Down
188 changes: 31 additions & 157 deletions tests/scriptlets/set-cookie.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,163 +38,37 @@ test('Checking if alias name works', (assert) => {
assert.strictEqual(codeByAdgParams, codeByUboParams, 'ubo name - ok');
});

test('Set cookie with valid value', (assert) => {
let cName = '__test-cookie_OK';
let cValue = 'OK';
runScriptlet(name, [cName, cValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(document.cookie.includes(cName) && document.cookie.includes(cValue), true, 'Cookie is set');
clearCookie(cName);

cName = '__test-cookie_true';
cValue = 'true';
runScriptlet(name, [cName, cValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(document.cookie.includes(cName) && document.cookie.includes(cValue), true, 'Cookie is set');
clearCookie(cName);

cName = '__test-cookie_false';
cValue = 'false';
runScriptlet(name, [cName, cValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(document.cookie.includes(cName) && document.cookie.includes(cValue), true, 'Cookie is set');
clearCookie(cName);

cName = '__test-cookie_no';
cValue = 'no';
runScriptlet(name, [cName, cValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(document.cookie.includes(cName) && document.cookie.includes(cValue), true, 'Cookie is set');
clearCookie(cName);

cName = '__test-cookie_n';
cValue = 'n';
runScriptlet(name, [cName, cValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(document.cookie.includes(cName) && document.cookie.includes(cValue), true, 'Cookie is set');
clearCookie(cName);

cName = '__test-cookie_Accept';
cValue = 'Accept';
runScriptlet(name, [cName, cValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(document.cookie.includes(cName) && document.cookie.includes(cValue), true, 'Cookie is set');
clearCookie(cName);

cName = '__test-cookie_Reject';
cValue = 'Reject';
runScriptlet(name, [cName, cValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(document.cookie.includes(cName) && document.cookie.includes(cValue), true, 'Cookie is set');
clearCookie(cName);

cName = '__test-cookie_allow';
cValue = 'allow';
runScriptlet(name, [cName, cValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(document.cookie.includes(cName) && document.cookie.includes(cValue), true, 'Cookie is set');
clearCookie(cName);

cName = '__test-cookie_deny';
cValue = 'deny';
runScriptlet(name, [cName, cValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(document.cookie.includes(cName) && document.cookie.includes(cValue), true, 'Cookie is set');
clearCookie(cName);

cName = '__test-cookie_dENy';
cValue = 'dENy';
runScriptlet(name, [cName, cValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(document.cookie.includes(cName) && document.cookie.includes(cValue), true, 'Cookie is set');
clearCookie(cName);

cName = '__test-cookie_0';
cValue = '0';
runScriptlet(name, [cName, cValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(document.cookie.includes(cName) && document.cookie.includes(cValue), true, 'Cookie is set');
clearCookie(cName);

cName = '__test-cookie_1';
cValue = '1';
runScriptlet(name, [cName, cValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(document.cookie.includes(cName) && document.cookie.includes(cValue), true, 'Cookie is set');
clearCookie(cName);

cName = '__test-cookie_on';
cValue = 'on';
runScriptlet(name, [cName, cValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(document.cookie.includes(cName) && document.cookie.includes(cValue), true, 'Cookie is set');
clearCookie(cName);

cName = '__test-cookie_off';
cValue = 'off';
runScriptlet(name, [cName, cValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(document.cookie.includes(cName) && document.cookie.includes(cValue), true, 'Cookie is set');
clearCookie(cName);

cName = '__test-cookie_accepted';
cValue = 'accepted';
runScriptlet(name, [cName, cValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(document.cookie.includes(cName) && document.cookie.includes(cValue), true, 'Cookie is set');
clearCookie(cName);

cName = '__test-cookie_notaccepted';
cValue = 'notaccepted';
runScriptlet(name, [cName, cValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(document.cookie.includes(cName) && document.cookie.includes(cValue), true, 'Cookie is set');
clearCookie(cName);

cName = '__test-cookie_rejected';
cValue = 'rejected';
runScriptlet(name, [cName, cValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(document.cookie.includes(cName) && document.cookie.includes(cValue), true, 'Cookie is set');
clearCookie(cName);

cName = '__test-cookie_allowed';
cValue = 'allowed';
runScriptlet(name, [cName, cValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(document.cookie.includes(cName) && document.cookie.includes(cValue), true, 'Cookie is set');
clearCookie(cName);

cName = '__test-cookie_disallow';
cValue = 'disallow';
runScriptlet(name, [cName, cValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(document.cookie.includes(cName) && document.cookie.includes(cValue), true, 'Cookie is set');
clearCookie(cName);

cName = '__test-cookie_enable';
cValue = 'enable';
runScriptlet(name, [cName, cValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(document.cookie.includes(cName) && document.cookie.includes(cValue), true, 'Cookie is set');
clearCookie(cName);

cName = '__test-cookie_enabled';
cValue = 'enabled';
runScriptlet(name, [cName, cValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(document.cookie.includes(cName) && document.cookie.includes(cValue), true, 'Cookie is set');
clearCookie(cName);

cName = '__test-cookie_disable';
cValue = 'disable';
runScriptlet(name, [cName, cValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(document.cookie.includes(cName) && document.cookie.includes(cValue), true, 'Cookie is set');
clearCookie(cName);

cName = '__test-cookie_disabled';
cValue = 'disabled';
const cookies = [
['__test-cookie_OK', 'OK'],
['__test-cookie_true', 'true'],
['__test-cookie_true', 't'],
['__test-cookie_false', 'false'],
['__test-cookie_false', 'f'],
['__test-cookie_no', 'no'],
['__test-cookie_n', 'n'],
['__test-cookie_Accept', 'Accept'],
['__test-cookie_Reject', 'Reject'],
['__test-cookie_allow', 'allow'],
['__test-cookie_deny', 'deny'],
['__test-cookie_dENy', 'dENy'],
['__test-cookie_0', '0'],
['__test-cookie_1', '1'],
['__test-cookie_on', 'on'],
['__test-cookie_off', 'off'],
['__test-cookie_accepted', 'accepted'],
['__test-cookie_notaccepted', 'notaccepted'],
['__test-cookie_rejected', 'rejected'],
['__test-cookie_allowed', 'allowed'],
['__test-cookie_disallow', 'disallow'],
['__test-cookie_enable', 'enable'],
['__test-cookie_enabled', 'enabled'],
['__test-cookie_disable', 'disable'],
['__test-cookie_disabled', 'disabled'],
['__test-cookie_necessary', 'necessary'],
['__test-cookie_required', 'required'],
];

test.each('Set cookie with valid value', cookies, (assert, [cName, cValue]) => {
runScriptlet(name, [cName, cValue]);
assert.strictEqual(window.hit, 'FIRED', 'Hit was fired');
assert.strictEqual(document.cookie.includes(cName) && document.cookie.includes(cValue), true, 'Cookie is set');
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2298,9 +2298,9 @@ camelcase@^6.2.0:
integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==

caniuse-lite@^1.0.30001251, caniuse-lite@^1.0.30001489:
version "1.0.30001498"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001498.tgz#84e4ee2d03e0e4f8a04a508853b75a980c703201"
integrity sha512-LFInN2zAwx3ANrGCDZ5AKKJroHqNKyjXitdV5zRIVIaQlXKj3GmxUKagoKsjqUfckpAObPCEWnk5EeMlyMWcgw==
version "1.0.30001581"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001581.tgz"
integrity sha512-whlTkwhqV2tUmP3oYhtNfaWGYHDdS3JYFQBKXxcUR9qqPWsRhFHhoISO2Xnl/g0xyKzht9mI1LZpiNWfMzHixQ==

chalk@^2.0.0:
version "2.4.2"
Expand Down

0 comments on commit 307fb6e

Please sign in to comment.