From ae142536aee950a41b223df740375e280763c00f Mon Sep 17 00:00:00 2001 From: Brandon Casey <2381475+brandonocasey@users.noreply.github.com> Date: Fri, 6 Sep 2019 12:00:45 -0400 Subject: [PATCH] fix: windows paths and test console error (#39) --- src/walk-manifest.js | 8 ++++---- test/resources/windows.m3u8 | 10 ++++++++++ test/unit/walk-manifest.spec.js | 24 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 test/resources/windows.m3u8 diff --git a/src/walk-manifest.js b/src/walk-manifest.js index 055ed3e..2d9df44 100644 --- a/src/walk-manifest.js +++ b/src/walk-manifest.js @@ -129,7 +129,7 @@ const parseKey = function(requestOptions, basedir, decrypt, resources, manifest, if (parent) { key.file = path.dirname(parent.file); } - key.file = path.join(key.file, fsSanitize(path.basename(key.uri))); + key.file = path.join(key.file, path.basename(fsSanitize(key.uri))); manifest.content = Buffer.from(manifest.content.toString().replace( key.uri, @@ -208,7 +208,7 @@ const walkPlaylist = function(options) { const manifest = {parent}; manifest.uri = uri; - manifest.file = path.join(basedir, fsSanitize(path.basename(uri))); + manifest.file = path.join(basedir, path.basename(fsSanitize(uri))); // if we are not the master playlist if (dashPlaylist && parent) { @@ -218,7 +218,7 @@ const walkPlaylist = function(options) { manifest.file = path.join( path.dirname(parent.file), 'manifest' + manifestIndex, - fsSanitize(path.basename(manifest.file)) + path.basename(fsSanitize(manifest.file)) ); // get the real uri of this playlist if (!isAbsolute(manifest.uri)) { @@ -298,7 +298,7 @@ const walkPlaylist = function(options) { return; } // put segments in manifest-name/segment-name.ts - s.file = path.join(path.dirname(manifest.file), fsSanitize(path.basename(s.uri))); + s.file = path.join(path.dirname(manifest.file), path.basename(fsSanitize(s.uri))); if (!isAbsolute(s.uri)) { s.uri = joinURI(path.dirname(manifest.uri), s.uri); diff --git a/test/resources/windows.m3u8 b/test/resources/windows.m3u8 new file mode 100644 index 0000000..f3df006 --- /dev/null +++ b/test/resources/windows.m3u8 @@ -0,0 +1,10 @@ +#EXTM3U +#EXT-X-PLAYLIST-TYPE:VOD +#EXT-X-TARGETDURATION:8 +#EXT-X-VERSION:6 +#EXT-X-INDEPENDENT-SEGMENTS +#EXT-X-MEDIA-SEQUENCE:0 +#EXTINF:2.000, +foo\\bar\\chunk_0.ts +#EXTINF:1.999, +foo/bar/chunk_1.ts diff --git a/test/unit/walk-manifest.spec.js b/test/unit/walk-manifest.spec.js index eeaab37..4c5fa28 100644 --- a/test/unit/walk-manifest.spec.js +++ b/test/unit/walk-manifest.spec.js @@ -24,12 +24,20 @@ const customError = function(errors) { describe('walk-manifest', function() { describe('walkPlaylist', function() { + /* eslint-disable no-console */ + beforeEach(function() { + this.oldError = console.error; + + console.error = () => {}; + }); afterEach(function() { + console.error = this.oldError; if (!nock.isDone()) { this.test.error(new Error('Not all nock interceptors were used!')); nock.cleanAll(); } }); + /* eslint-enable no-console */ it('should return just top level error for bad m3u8 uri', function(done) { nock(TEST_URL) @@ -85,6 +93,22 @@ describe('walk-manifest', function() { }); }); + it('should return just segments for m3u8 with windows paths', function(done) { + nock(TEST_URL) + .get('/test.m3u8') + .replyWithFile(200, `${process.cwd()}/test/resources/windows.m3u8`); + + const options = {decrypt: false, basedir: '.', uri: TEST_URL + '/test.m3u8', requestRetryMaxAttempts: 0}; + + walker(options) + .then(function(resources) { + + assert.equal(resources[1].file, 'chunk_0.ts'); + assert.equal(resources[2].file, 'chunk_1.ts'); + done(); + }); + }); + it('should return correct paths for m3u8', function(done) { nock(TEST_URL) .get('/test/test.m3u8')