Error while exporting course with too long filename

This commit is contained in:
noraiz-anwar
2016-12-27 15:46:18 +05:00
parent 74a0d76956
commit 9c139a87a6
4 changed files with 58 additions and 4 deletions

View File

@@ -215,6 +215,42 @@ function($, _, Utils, _str) {
});
});
});
describe('Too long arguments ', function() {
var longFileName = (function() {
var text = '';
var possibleChars = 'abcdefghijklmnopqrstuvwxyz';
/* eslint vars-on-top: 0 */
for (var i = 0; i < 255; i++) {
text += possibleChars.charAt(Math.floor(Math.random() * possibleChars.length));
}
return text;
}()),
html5LongUrls = (function(videoName) {
var links = [
'http://somelink.com/%s?param=1&param=2#hash',
'http://somelink.com/%s#hash',
'http://somelink.com/%s?param=1&param=2',
'http://somelink.com/%s',
'ftp://somelink.com/%s',
'https://somelink.com/%s',
'https://somelink.com/sub/sub/%s',
'http://cdn.somecdn.net/v/%s',
'somelink.com/%s',
'%s'
];
return $.map(links, function(link) {
return _str.sprintf(link, videoName);
});
}(longFileName));
$.each(html5LongUrls, function(index, link) {
it(link, function() {
var result = Utils.parseHTML5Link(link);
expect(result.video.length).toBe(150);
});
});
});
});
it('Method: getYoutubeLink', function() {

View File

@@ -110,6 +110,7 @@ define(['jquery', 'underscore', 'jquery.ajaxQueue'], function($) {
*/
var _videoLinkParser = (function() {
var cache = {};
var maxVideoNameLength = 150;
return function(url) {
if (typeof url !== 'string') {
@@ -129,7 +130,10 @@ define(['jquery', 'underscore', 'jquery.ajaxQueue'], function($) {
match = link.pathname.match(/\/{1}([^\/]+)\.([^\/]+)$/);
if (match) {
cache[url] = {
video: match[1],
/* avoid too long video name, as it will be used as filename for video's transcript
and a filename can not be more that 255 chars, limiting here to 150.
*/
video: match[1].slice(0, maxVideoNameLength),
type: match[2]
};
} else {
@@ -139,7 +143,7 @@ define(['jquery', 'underscore', 'jquery.ajaxQueue'], function($) {
match = link.pathname.match(/\/{1}([^\/\.]+)$/);
if (match) {
cache[url] = {
video: match[1],
video: match[1].slice(0, maxVideoNameLength),
type: 'other'
};
}