Commit db213bf3 by polesye

BLD-967: Fix regExp.

parent 926ce567
...@@ -5,6 +5,8 @@ These are notable changes in edx-platform. This is a rolling list of changes, ...@@ -5,6 +5,8 @@ These are notable changes in edx-platform. This is a rolling list of changes,
in roughly chronological order, most recent first. Add your entries at or near in roughly chronological order, most recent first. Add your entries at or near
the top. Include a label indicating the component affected. the top. Include a label indicating the component affected.
Blades: Fix Youtube regular expression in video player editor. BLD-967.
Blades: Fix displaying transcripts on touch devices. BLD-1033. Blades: Fix displaying transcripts on touch devices. BLD-1033.
Blades: Tolerance expressed in percentage now computes correctly. BLD-522. Blades: Tolerance expressed in percentage now computes correctly. BLD-522.
......
define( define(
[ [
"jquery", "underscore", 'jquery', 'underscore',
"js/views/video/transcripts/utils", 'js/views/video/transcripts/utils',
"underscore.string", "xmodule", "jasmine-jquery" 'underscore.string', 'xmodule', 'jasmine-jquery'
], ],
function ($, _, Utils, _str) { function ($, _, Utils, _str) {
describe('Transcripts.Utils', function () { 'use strict';
describe('Transcripts.Utils', function () {
var videoId = 'OEoXaMPEzfM', var videoId = 'OEoXaMPEzfM',
ytLinksList = (function (id) { ytLinksList = (function (id) {
var links = [ var links = [
...@@ -33,6 +34,7 @@ function ($, _, Utils, _str) { ...@@ -33,6 +34,7 @@ function ($, _, Utils, _str) {
'http://somelink.com/%s.%s', 'http://somelink.com/%s.%s',
'ftp://somelink.com/%s.%s', 'ftp://somelink.com/%s.%s',
'https://somelink.com/%s.%s', 'https://somelink.com/%s.%s',
'http://cdn.somecdn.net/v/%s.%s',
'somelink.com/%s.%s', 'somelink.com/%s.%s',
'%s.%s' '%s.%s'
], ],
...@@ -214,7 +216,7 @@ function ($, _, Utils, _str) { ...@@ -214,7 +216,7 @@ function ($, _, Utils, _str) {
describe('Method: parseLink', function () { describe('Method: parseLink', function () {
var resultDataDict = { var resultDataDict = {
'html5': { 'html5': {
link: html5LinksList['mp4'][0], link: html5LinksList.mp4[0],
resp: { resp: {
mode: 'html5', mode: 'html5',
video: html5FileName, video: html5FileName,
...@@ -260,5 +262,5 @@ function ($, _, Utils, _str) { ...@@ -260,5 +262,5 @@ function ($, _, Utils, _str) {
}); });
}); });
}); });
}); });
}); });
define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) { define(['jquery', 'underscore', 'jquery.ajaxQueue'], function($) {
var Utils = (function () { 'use strict';
return (function () {
var Storage = {}; var Storage = {};
/** /**
* @function
*
* Adds some data to the Storage object. If data with existent `data_id` * Adds some data to the Storage object. If data with existent `data_id`
* is added, nothing happens. * is added, nothing happens.
* * @function
* @param {string} data_id Unique identifier for the data. * @param {String} data_id Unique identifier for the data.
* @param {any} data Data that should be stored. * @param {Any} data Data that should be stored.
* * @return {Object} Object itself for chaining.
* @returns {object} Object itself for chaining.
*/ */
Storage.set = function (data_id, data) { Storage.set = function (data_id, data) {
Storage[data_id] = data; Storage[data_id] = data;
...@@ -20,13 +18,10 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) { ...@@ -20,13 +18,10 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) {
}; };
/** /**
* @function
*
* Return data from the Storage object by identifier. * Return data from the Storage object by identifier.
* * @function
* @param {string} data_id Unique identifier of the data. * @param {String} data_id Unique identifier of the data.
* * @return {Any} Stored data.
* @returns {any} Stored data.
*/ */
Storage.get= function (data_id) { Storage.get= function (data_id) {
...@@ -35,13 +30,10 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) { ...@@ -35,13 +30,10 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) {
/** /**
* @function
*
* Deletes data from the Storage object by identifier. * Deletes data from the Storage object by identifier.
* * @function
* @param {string} data_id Unique identifier of the data. * @param {String} data_id Unique identifier of the data.
* * @return {Boolean} Boolean value that indicate if data is removed.
* @returns {boolean} Boolean value that indicate if data is removed.
*/ */
Storage.remove = function (data_id) { Storage.remove = function (data_id) {
...@@ -49,17 +41,14 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) { ...@@ -49,17 +41,14 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) {
}; };
/** /**
* @function
*
* Returns model from collection by 'field_name' property. * Returns model from collection by 'field_name' property.
* * @function
* @param {object} collection The model (CMS.Models.Metadata) containing * @param {Object} collection The model (CMS.Models.Metadata) information
* information about metadata setting editors. * about metadata setting editors.
* @param {string} field_name Name of field that should be found. * @param {String} field_name Name of field that should be found.
* * @return {
* @returns { * Object: When model exist.
* object: when model exist, * Undefined: When model doesn't exist.
* undefined: when model doesn't exist.
* } * }
*/ */
var _getField = function (collection, field_name) { var _getField = function (collection, field_name) {
...@@ -75,10 +64,8 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) { ...@@ -75,10 +64,8 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) {
}; };
/** /**
* @function
*
* Parses Youtube link and return video id. * Parses Youtube link and return video id.
* * @function
* These are the types of URLs supported: * These are the types of URLs supported:
* http://www.youtube.com/watch?v=OEoXaMPEzfM&feature=feedrec_grec_index * http://www.youtube.com/watch?v=OEoXaMPEzfM&feature=feedrec_grec_index
* http://www.youtube.com/user/IngridMichaelsonVEVO#p/a/u/1/OEoXaMPEzfM * http://www.youtube.com/user/IngridMichaelsonVEVO#p/a/u/1/OEoXaMPEzfM
...@@ -87,17 +74,16 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) { ...@@ -87,17 +74,16 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) {
* http://www.youtube.com/embed/OEoXaMPEzfM?rel=0 * http://www.youtube.com/embed/OEoXaMPEzfM?rel=0
* http://www.youtube.com/watch?v=OEoXaMPEzfM * http://www.youtube.com/watch?v=OEoXaMPEzfM
* http://youtu.be/OEoXaMPEzfM * http://youtu.be/OEoXaMPEzfM
* * @param {String} url Url that should be parsed.
* @param {string} url Url that should be parsed. * @return {
* * String: Video Id.
* @returns { * Undefined: When url has incorrect format or argument is
* string: Video Id,
* undefined: when url has incorrect format or argument is
* non-string, video id's length is not equal 11. * non-string, video id's length is not equal 11.
* } * }
*/ */
var _youtubeParser = (function () { var _youtubeParser = (function () {
var cache = {}; var cache = {},
regExp = /(?:http|https|)(?:\:\/\/|)(?:www.|)(?:youtu\.be\/|youtube\.com(?:\/embed\/|\/v\/|\/watch\?v=|\/ytscreeningroom\?v=|\/feeds\/api\/videos\/|\/user\S*[^\w\-\s]|\S*[^\w\-\s]))([\w\-]{11})[a-z0-9;:@#?&%=+\/\$_.-]*/i;
return function (url) { return function (url) {
if (typeof url !== 'string') { if (typeof url !== 'string') {
...@@ -109,22 +95,20 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) { ...@@ -109,22 +95,20 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) {
return cache[url]; return cache[url];
} }
var regExp = /.*(?:youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/;
var match = url.match(regExp); var match = url.match(regExp);
cache[url] = (match && match[1].length === 11) ? match[1] : void(0); cache[url] = (match && match[1].length === 11) ?
match[1] :
void(0);
return cache[url]; return cache[url];
}; };
}()); }());
/** /**
* @function
*
* Parses links with html5 video sources in mp4 or webm formats. * Parses links with html5 video sources in mp4 or webm formats.
* * @function
* @param {string} url Url that should be parsed. * @param {String} url Url that should be parsed.
* * @return {
* @returns {
* object: Object with information about the video * object: Object with information about the video
* (file name, video type), * (file name, video type),
* undefined: when url has incorrect format or argument is * undefined: when url has incorrect format or argument is
...@@ -151,27 +135,31 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) { ...@@ -151,27 +135,31 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) {
match = link.pathname match = link.pathname
.split('/') .split('/')
.pop() .pop()
.match(/(.+)\.(mp4|webm)$/); .match(/(.+)\.(mp?4v?|webm)$/);
if (match) { if (match) {
cache[url] = { cache[url] = {
video: match[1], video: match[1],
type: match[2] type: match[2]
}; };
} } /*else {
cache[url] = {
video: link.pathname
.split('/')
.pop(),
type: 'other'
};
}*/
return cache[url]; return cache[url];
}; };
}()); }());
/** /**
* @function
*
* Facade function that parses html5 and youtube links. * Facade function that parses html5 and youtube links.
* * @function
* @param {string} url Url that should be parsed. * @param {String} url Url that should be parsed.
* * @return {
* @returns {
* object: Object with information about the video: * object: Object with information about the video:
* { * {
* mode: "youtube|html5|incorrect", * mode: "youtube|html5|incorrect",
...@@ -207,32 +195,23 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) { ...@@ -207,32 +195,23 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) {
}; };
/** /**
* @function
*
* Returns short-hand youtube url. * Returns short-hand youtube url.
* * @function
* @param {string} video_id Youtube Video Id that will be added to the link. * @param {string} video_id Youtube Video Id that will be added to the
* * link.
* @returns {string} Short-hand Youtube url. * @return {string} Short-hand Youtube url.
* * @examples
* @example
* _getYoutubeLink('OEoXaMPEzfM'); => 'http://youtu.be/OEoXaMPEzfM' * _getYoutubeLink('OEoXaMPEzfM'); => 'http://youtu.be/OEoXaMPEzfM'
*/ */
var _getYoutubeLink = function (video_id) { var _getYoutubeLink = function (video_id) {
return 'http://youtu.be/' + video_id; return 'http://youtu.be/' + video_id;
}; };
/** /**
* @function
*
* Returns list of objects with information about the passed links. * Returns list of objects with information about the passed links.
* * @function
* @param {array} links List of links that will be processed. * @param {array} links List of links that will be processed.
*
* @returns {array} List of objects. * @returns {array} List of objects.
*
* @examples * @examples
* var links = [ * var links = [
* 'http://youtu.be/OEoXaMPEzfM', * 'http://youtu.be/OEoXaMPEzfM',
...@@ -246,7 +225,6 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) { ...@@ -246,7 +225,6 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) {
* {mode: `html5`, type: `mp4`, ...}, * {mode: `html5`, type: `mp4`, ...},
* {mode: `html5`, type: `webm`, ...} * {mode: `html5`, type: `webm`, ...}
* ] * ]
*
*/ */
var _getVideoList = function (links) { var _getVideoList = function (links) {
if ($.isArray(links)) { if ($.isArray(links)) {
...@@ -267,14 +245,11 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) { ...@@ -267,14 +245,11 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) {
/** /**
* @function
*
* Synchronizes 2 Backbone collections by 'field_name' property. * Synchronizes 2 Backbone collections by 'field_name' property.
* * @function
* @param {object} fromCollection Collection with which synchronization * @param {Object} fromCollection Collection with which synchronization will
* will happens. * happens.
* @param {object} toCollection Collection which will synchronized. * @param {Object} toCollection Collection which will synchronized.
*
*/ */
var _syncCollections = function (fromCollection, toCollection) { var _syncCollections = function (fromCollection, toCollection) {
fromCollection.each(function (m) { fromCollection.each(function (m) {
...@@ -289,21 +264,17 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) { ...@@ -289,21 +264,17 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) {
}; };
/** /**
* @function
*
* Sends Ajax requests in appropriate format. * Sends Ajax requests in appropriate format.
* * @function
* @param {string} action Action that will be invoked on server. Is a part * @param {String} action Action that will be invoked on server.
* of url. * @param {String} component_locator the locator of component.
* @param {string} component_locator the locator of component. * @param {Array} videoList List of object with information about inserted
* @param {array} videoList List of object with information about inserted
* urls. * urls.
* @param {object} extraParams Extra parameters that can be send to the * @param {Object} extraParams Extra parameters that can be send to the
* server * server.
* * @return {Object} XMLHttpRequest object. Using this object, we can
* @returns {object} XMLHttpRequest object. Using this object, we can attach * attach callbacks to AJAX request events (for example on 'done',
* callbacks to AJAX request events (for example on 'done', 'fail', * 'fail', etc.).
* etc.).
*/ */
var _command = (function () { var _command = (function () {
// We will store the XMLHttpRequest object that $.ajax() function // We will store the XMLHttpRequest object that $.ajax() function
...@@ -314,7 +285,7 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) { ...@@ -314,7 +285,7 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) {
// _command() function. // _command() function.
var xhr = null; var xhr = null;
return function (action, component_locator, videoList, extraParams) { return function (action, locator, videoList, extraParams) {
var params, data; var params, data;
if (extraParams) { if (extraParams) {
...@@ -326,7 +297,7 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) { ...@@ -326,7 +297,7 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) {
} }
data = $.extend( data = $.extend(
{ locator: component_locator }, { locator: locator },
{ videos: videoList }, { videos: videoList },
params params
); );
...@@ -357,7 +328,5 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) { ...@@ -357,7 +328,5 @@ define(["jquery", "underscore", "jquery.ajaxQueue"], function($, _) {
remove: Storage.remove remove: Storage.remove
} }
}; };
}()); }());
return Utils;
}); });
...@@ -37,6 +37,7 @@ from .video_handlers import VideoStudentViewHandlers, VideoStudioViewHandlers ...@@ -37,6 +37,7 @@ from .video_handlers import VideoStudentViewHandlers, VideoStudioViewHandlers
from urlparse import urlparse from urlparse import urlparse
def get_ext(filename): def get_ext(filename):
# Prevent incorrectly parsing urls like 'http://abc.com/path/video.mp4?xxxx'. # Prevent incorrectly parsing urls like 'http://abc.com/path/video.mp4?xxxx'.
path = urlparse(filename).path path = urlparse(filename).path
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment