Skip to content

Commit

Permalink
Merge branch 'master' into feature/AG-30879
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamWr committed May 20, 2024
2 parents a6f85a7 + 45a42cc commit e7a0a2d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic

- `ruleText` option in the `IConfiguration`

### Fixed

- `set-attr` value cannot be set to minimum `0` and maximum `32767` possible value [#425]

[Unreleased]: https://github.com/AdguardTeam/Scriptlets/compare/v1.10.25...HEAD
[#425]: https://github.com/AdguardTeam/Scriptlets/issues/425
[#420]: https://github.com/AdguardTeam/Scriptlets/issues/420
[#410]: https://github.com/AdguardTeam/Scriptlets/issues/410
[#382]: https://github.com/AdguardTeam/Scriptlets/issues/382
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adguard/scriptlets",
"version": "1.10.29",
"version": "1.10.30",
"description": "AdGuard's JavaScript library of Scriptlets and Redirect resources",
"scripts": {
"build": "babel-node -x .js,.ts scripts/build.js",
Expand Down
4 changes: 2 additions & 2 deletions src/scriptlets/set-attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ export function setAttr(source, selector, attr, value = '') {

const isValidValue = value.length === 0
|| (!nativeIsNaN(parseInt(value, 10))
&& parseInt(value, 10) > 0
&& parseInt(value, 10) < 32767)
&& parseInt(value, 10) >= 0
&& parseInt(value, 10) <= 32767)
|| allowedValues.includes(value.toLowerCase());

if (!shouldCopyValue && !isValidValue) {
Expand Down
32 changes: 32 additions & 0 deletions tests/scriptlets/set-attr.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,38 @@ test('selector + attr + eligible number', (assert) => {
}, 30);
});

test('selector + attr + 0 (minimum possible value)', (assert) => {
const value = '0';
const { targetSelector, targetElem, mismatchElem } = context;
const scriptletArgs = [targetSelector, TARGET_ATTR_NAME, value];

runScriptlet(name, scriptletArgs);

assert.strictEqual(targetElem.getAttribute(TARGET_ATTR_NAME), value, `New attr value ${value} is correct`);
assert.strictEqual(
mismatchElem.getAttribute(TARGET_ATTR_NAME),
null,
`Attr ${TARGET_ATTR_NAME} is not added to mismatch element`,
);
assert.strictEqual(window.hit, 'FIRED', 'hit function has been called');
});

test('selector + attr + 32767 (maximum possible value)', (assert) => {
const value = '32767';
const { targetSelector, targetElem, mismatchElem } = context;
const scriptletArgs = [targetSelector, TARGET_ATTR_NAME, value];

runScriptlet(name, scriptletArgs);

assert.strictEqual(targetElem.getAttribute(TARGET_ATTR_NAME), value, `New attr value ${value} is correct`);
assert.strictEqual(
mismatchElem.getAttribute(TARGET_ATTR_NAME),
null,
`Attr ${TARGET_ATTR_NAME} is not added to mismatch element`,
);
assert.strictEqual(window.hit, 'FIRED', 'hit function has been called');
});

test('selector + attr + empty string', (assert) => {
const value = '';
const { targetSelector, targetElem, mismatchElem } = context;
Expand Down

0 comments on commit e7a0a2d

Please sign in to comment.