Skip to content

Commit

Permalink
AG-25455 Improve m3u-prune — content is not pruned if contains carria…
Browse files Browse the repository at this point in the history
…ge return. #354

Squashed commit of the following:

commit 5c5ff26
Merge: b96602b 514c7fe
Author: Adam Wróblewski <adam@adguard.com>
Date:   Tue Sep 12 14:22:54 2023 +0200

    Merge branch 'master' into fix/AG-25455

commit b96602b
Author: Adam Wróblewski <adam@adguard.com>
Date:   Tue Sep 12 14:20:34 2023 +0200

    Better fix for issue with CRLF

commit 678a302
Author: Adam Wróblewski <adam@adguard.com>
Date:   Wed Sep 6 09:27:57 2023 +0200

    Improve 'm3u-prune' — content is not pruned if contains carriage return
  • Loading branch information
AdamWr committed Sep 13, 2023
1 parent 514c7fe commit 23b2bfd
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- issue with not pruning in `m3u-prune` scriptlet if file contains carriage return
[#354](https://github.com/AdguardTeam/Scriptlets/issues/354)
- issue with not overriding value in `set-constant` (only partially, for cases where single scriptlet is used)
[#330](https://github.com/AdguardTeam/Scriptlets/issues/330)

Expand Down
2 changes: 1 addition & 1 deletion src/scriptlets/m3u-prune.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export function m3uPrune(source, propsToRemove, urlToMatch = '') {
*/
// TODO: make it compatible with $hls modifier
const pruneM3U = (text) => {
let lines = text.split(/\n\r|\n|\r/);
let lines = text.split(/\r?\n/);

if (text.includes(COMCAST_AD_MARKER.VMAP_AD_BREAK)) {
lines = pruneVmapBlock(lines);
Expand Down
22 changes: 22 additions & 0 deletions tests/scriptlets/m3u-prune.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const M3U8_OBJECTS_PATH_03 = './test-files/manifestM3U8-03.m3u8';
// From sbs.com - https://github.com/AdguardTeam/AdguardFilters/issues/88692
// https://regex101.com/r/Kxtnng/1
const M3U8_OBJECTS_PATH_04 = './test-files/manifestM3U8-04.m3u8';
// https://github.com/AdguardTeam/Scriptlets/issues/354
const M3U8_OBJECTS_CR = './test-files/manifestM3U8-carriage-return.m3u8';

const nativeFetch = fetch;
const nativeXhrOpen = XMLHttpRequest.prototype.open;
const nativeConsole = console.log;
Expand Down Expand Up @@ -355,6 +358,25 @@ if (!isSupported) {
done();
});

test('fetch - remove ads carriage return', async (assert) => {
const M3U8_PATH = M3U8_OBJECTS_CR;
const MATCH_DATA = 'advert.com';

runScriptlet(name, [MATCH_DATA]);

const done = assert.async();

const response = await fetch(M3U8_PATH);
const responseM3U8 = await response.text();

assert.notOk(
responseM3U8.includes('advert.com'),
'check if "advert.com" has been removed',
);
assert.strictEqual(window.hit, 'FIRED', 'hit function fired');
done();
});

test('xhr - no prune 1', async (assert) => {
const METHOD = 'GET';
const M3U8_PATH = M3U8_OBJECTS_PATH_01;
Expand Down
15 changes: 15 additions & 0 deletions tests/scriptlets/test-files/manifestM3U8-carriage-return.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#EXTM3U
#EXT-X-VERSION:4
#EXT-X-TARGETDURATION:6
#EXT-X-MEDIA-SEQUENCE:1
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:5.005,
https://advert.com/foo.ts
#EXT-X-DISCONTINUITY
#EXTINF:6,
https://example.com/segment1.ts
#EXTINF:6,
https://example.com/segment2.ts
#EXTINF:6,
https://example.com/segment3.ts
#EXT-X-DISCONTINUITY

0 comments on commit 23b2bfd

Please sign in to comment.