Skip to content

Commit

Permalink
fix: Cut to 200 characters to prevent ENAMETOOLONG
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey committed Jul 19, 2019
1 parent 0139442 commit b9f536f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/walk-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ const path = require('path');

// replace invalid http/fs characters with valid representations
const fsSanitize = function(filepath) {
return filepath
.replace(/\?/g, '-questionmark-');
return filepath.split(path.delimiter).map((p) => p
.replace(/\?/g, '-questionmark-')
// max filepath is 255 on OSX/linux, and 260 on windows, 255 is fine for both
.substring(0, 255)
).join('');
};

const joinURI = function(absolute, relative) {
Expand Down
17 changes: 17 additions & 0 deletions test/resources/long-path.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#EXTM3U
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-TARGETDURATION:8
#EXT-X-VERSION:6
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-MEDIA-SEQUENCE:0
chunk_0.ts?token=OYKrjKeGaskhhsmf8E7aoUftbIfXZo0ucm9qebBFsXG5yepliwyfwKIf4zTGqMocHsTJePF91V17ZJ4h8A7mS3ysNSOcjKQT2oAVJmfD3vJIwdDfD0mZqlA9jQOOWwXnLy0UQtn9V2eYXlNAdIc9w8yDFPxDp509vJC9lurHWewql6eg22drnACC2rEDOXYit0I3CqOaVRvLSIqG0quUda5CoDn7vmaCBlvsBA0MEoWQSG0TEmDtdTT6DP8vUCC7BTtr9Zaxo5l9QYnWyNMzZNszjijCoKq8LsAi95WIo2n9

#EXTINF:2.000,
/testOYKrjKeGaskhhsmf8E7aoUftbIfXZo0ucm9qebBFsXG5yepliwyfwKIf4zTGqMocHsTJePF91V17ZJ4h8A7mS3ysNSOcjKQT2oAVJmfD3vJIwdDfD0mZqlA9jQOOWwXnLy0UQtn9V2eYXlNAdIc9w8yDFPxDp509vJC9lurHW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IfXZo0ucm9qebBFsXG5yepliwyfwKIf4zTGqMocHsTJePF91V17ZJ4h8A7mS3ysNSOcjKQT2oAVJmfD3vJIwdDfD0mZqlA9jQOOWwXnLy0UQtn9V2eYXlNAdIc9w8yDFPxDp509vJC9lurHWewql6eg22drnACC2rEDOXYit0I3CqOaVRvLSIqG0quUda5CoDn7vmaCBlvsBA0MEoWQSG0TEmDtdTT6DP8vUCC7BTtr9Zaxo5l9QYnWyNMzZNszjijCoKq8LsAi95WIo2n9
#EXTINF:2.000,
http://manifest-list-test.com/testOYKrjKeGaskhhsmf8E7aoUftbIfXZo0ucm9qebBFsXG5yepliwyfwKIf4zTGqMocHsTJePF91V17ZJ4h8A7mS3ysNSOcjKQT2oAVJmfD3vJIwdDfD0mZqlA9jQOOWwXnLy0UQtn9V2eYXlNAdIc9w8yDFPxDp509vJC9lurHWewql6eg22drnACC2rEDOXYit0I3CqOaVRvLSIqG0quUda5CoDn7vmaCBlvsBA0MEoWQSG0TEmDtdTT6DP8vUCC7BTtr9Zaxo5l9QYnWyNMzZNszjijCoKq8LsAi95WIo2n9/chunk_3.ts?token=OYKrjKeGaskhhsmf8E7aoUftbIfXZo0ucm9qebBFsXG5yepliwyfwKIf4zTGqMocHsTJePF91V17ZJ4h8A7mS3ysNSOcjKQT2oAVJmfD3vJIwdDfD0mZqlA9jQOOWwXnLy0UQtn9V2eYXlNAdIc9w8yDFPxDp509vJC9lurHWewql6eg22drnACC2rEDOXYit0I3CqOaVRvLSIqG0quUda5CoDn7vmaCBlvsBA0MEoWQSG0TEmDtdTT6DP8vUCC7BTtr9Zaxo5l9QYnWyNMzZNszjijCoKq8LsAi95WIo2n9
#EXTINF:2.000,

46 changes: 46 additions & 0 deletions test/unit/walk-manifest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,52 @@ describe('walk-manifest', function() {
});
});

it('should shorten paths that will be too long', function() {
// string used in long-path.m3u8
const longPathRandom = 'OYKrjKeGaskhhsmf8E7aoUftbIfXZo0ucm9qebBFsXG5yepliwyfwKIf4zTGqMocHsTJePF91V17ZJ4h8A7mS3ysNSOcjKQT2oAVJmfD3vJIwdDfD0mZqlA9jQOOWwXnLy0UQtn9V2eYXlNAdIc9w8yDFPxDp509vJC9lurHWewql6eg22drnACC2rEDOXYit0I3CqOaVRvLSIqG0quUda5CoDn7vmaCBlvsBA0MEoWQSG0TEmDtdTT6DP8vUCC7BTtr9Zaxo5l9QYnWyNMzZNszjijCoKq8LsAi95WIo2n9';
const longChunkPath = `chunk_REPLACE.ts-questionmark-token=${longPathRandom.substring(0, 255 - 30)}`;

nock(TEST_URL)
.get(`/test${longPathRandom}/test.m3u8?token=${longPathRandom}`)
.replyWithFile(200, `${process.cwd()}/test/resources/long-path.m3u8`);

const options = {
decrypt: false,
basedir: '.',
uri: `${TEST_URL}/test${longPathRandom}/test.m3u8?token=${longPathRandom}`,
requestRetryMaxAttempts: 0
};

return walker(options)
.then(function(resources) {
assert.equal(
resources[0].file,
`test.m3u8-questionmark-token=${longPathRandom.substring(0, 255 - 29)}`,
'manifest file is correct'
);
assert.equal(
resources[1].file,
`${longChunkPath.replace('REPLACE', '0')}`,
'chunk 0 is correct'
);
assert.equal(
resources[2].file,
`${longChunkPath.replace('REPLACE', '1')}`,
'chunk 1 is correct'
);
assert.equal(
resources[3].file,
`${longChunkPath.replace('REPLACE', '2')}`,
'chunk 2 is correct'
);
assert.equal(
resources[4].file,
`${longChunkPath.replace('REPLACE', '3')}`,
'chunk 3 is correct'
);
});
});

it('should return fmp4/ts segments and init segment for fmp4 m3u8', function(done) {
nock(TEST_URL)
.get('/test.m3u8')
Expand Down

0 comments on commit b9f536f

Please sign in to comment.