Skip to content

Commit

Permalink
Do nothing if response type is not a string
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamWr committed Jan 26, 2023
1 parent c6ac46a commit 602a502
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/scriptlets/m3u-prune.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,18 @@ export function m3uPrune(source, propsToRemove, urlToMatch) {

/**
* Determines if text contains "#EXTM3U" or "VMAP_AD_BREAK"
* @param {string} text
* @param {*} text
* @returns {boolean}
*/
const isM3U = (text) => {
// Check if "text" starts with "#EXTM3U" or with "VMAP_AD_BREAK"
// If so, then it might be an M3U file and should be pruned or logged
const trimmedText = text.trim();
if (startsWith(trimmedText, AD_MARKER.EXTM3U)
|| startsWith(trimmedText, COMCAST_AD_MARKER.VMAP_AD_BREAK)) {
return true;
if (typeof text === 'string') {
// Check if "text" starts with "#EXTM3U" or with "VMAP_AD_BREAK"
// If so, then it might be an M3U file and should be pruned or logged
const trimmedText = text.trim();
if (startsWith(trimmedText, AD_MARKER.EXTM3U)
|| startsWith(trimmedText, COMCAST_AD_MARKER.VMAP_AD_BREAK)) {
return true;
}
}
return false;
};
Expand Down
18 changes: 18 additions & 0 deletions tests/scriptlets/m3u-prune.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,4 +507,22 @@ if (!isSupported) {
};
xhr.send();
});

test('xhr - do nothing if response type is not a string', async (assert) => {
const METHOD = 'GET';
const M3U8_PATH = M3U8_OBJECTS_PATH_01;
const done = assert.async();

runScriptlet(name);

const xhr = new XMLHttpRequest();
xhr.open(METHOD, M3U8_PATH);
xhr.responseType = 'blob';
xhr.onload = () => {
assert.ok(xhr.response instanceof Blob, 'Blob response');
assert.strictEqual(window.hit, undefined, 'should not hit');
done();
};
xhr.send();
});
}

0 comments on commit 602a502

Please sign in to comment.