diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c6316a1..94f0df35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/scriptlets/m3u-prune.js b/src/scriptlets/m3u-prune.js index e4ba056f..b310af10 100644 --- a/src/scriptlets/m3u-prune.js +++ b/src/scriptlets/m3u-prune.js @@ -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); diff --git a/tests/scriptlets/m3u-prune.test.js b/tests/scriptlets/m3u-prune.test.js index 0e1f9b02..227ef050 100644 --- a/tests/scriptlets/m3u-prune.test.js +++ b/tests/scriptlets/m3u-prune.test.js @@ -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; @@ -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; diff --git a/tests/scriptlets/test-files/manifestM3U8-carriage-return.m3u8 b/tests/scriptlets/test-files/manifestM3U8-carriage-return.m3u8 new file mode 100644 index 00000000..84f0c28e --- /dev/null +++ b/tests/scriptlets/test-files/manifestM3U8-carriage-return.m3u8 @@ -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