Skip to content

Commit

Permalink
fix: windows paths and test console error (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored Sep 6, 2019
1 parent 6452b11 commit ae14253
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/walk-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -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)) {
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions test/resources/windows.m3u8
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions test/unit/walk-manifest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit ae14253

Please sign in to comment.