Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions www/addons/mod/book/services/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ angular.module('mm.addons.mod_book')
* @name $mmaModBook
*/
.factory('$mmaModBook', function($mmFilepool, $mmSite, $mmFS, $http, $log, $q, $mmSitesManager, $mmUtil, mmaModBookComponent,
$mmCourse) {
$mmCourse, $mmText) {
$log = $log.getInstance('$mmaModBook');

var self = {};
Expand Down Expand Up @@ -278,7 +278,7 @@ angular.module('mm.addons.mod_book')
// Remove the chapter folder from the path and add the filename.
key = content.filepath.replace('/' + chapter + '/', '') + content.filename;
}
map[chapter].paths[decodeURIComponent(key)] = content.fileurl;
map[chapter].paths[$mmText.decodeURIComponent(key)] = content.fileurl;
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions www/addons/mod/page/services/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ angular.module('mm.addons.mod_page')
* @ngdoc service
* @name $mmaModPage
*/
.factory('$mmaModPage', function($mmFilepool, $mmSite, $mmFS, $http, $log, $q, $mmSitesManager, $mmUtil, mmaModPageComponent) {
.factory('$mmaModPage', function($mmFilepool, $mmSite, $mmFS, $http, $log, $q, $mmSitesManager, $mmUtil, $mmText,
mmaModPageComponent) {
$log = $log.getInstance('$mmaModPage');

var self = {};
Expand Down Expand Up @@ -55,7 +56,7 @@ angular.module('mm.addons.mod_page')
// Add the folders without the leading slash.
key = content.filepath.substr(1) + key;
}
paths[decodeURIComponent(key)] = url;
paths[$mmText.decodeURIComponent(key)] = url;
}
});

Expand Down
4 changes: 2 additions & 2 deletions www/addons/mod/resource/services/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ angular.module('mm.addons.mod_resource')
* @name $mmaModResource
*/
.factory('$mmaModResource', function($mmFilepool, $mmSite, $mmUtil, $mmFS, $http, $log, $q, $sce, $mmApp, $mmSitesManager,
mmaModResourceComponent, mmCoreNotDownloaded, mmCoreDownloading, mmCoreDownloaded) {
$mmText, mmaModResourceComponent, mmCoreNotDownloaded, mmCoreDownloading, mmCoreDownloaded) {
$log = $log.getInstance('$mmaModResource');

var self = {};
Expand Down Expand Up @@ -97,7 +97,7 @@ angular.module('mm.addons.mod_resource')
indexUrl = url;
} else {
// Any other file in the resource.
paths[decodeURIComponent(fullpath)] = url;
paths[$mmText.decodeURIComponent(fullpath)] = url;
}
});

Expand Down
4 changes: 2 additions & 2 deletions www/addons/mod/wiki/services/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ angular.module('mm.addons.mod_wiki')
*/
.factory('$mmaModWikiHandlers', function($mmCourse, $mmaModWiki, $state, $mmContentLinksHelper, $mmCourseHelper, $mmUtil, $q,
mmaModWikiComponent, $mmaModWikiPrefetchHandler, mmCoreDownloading, mmCoreNotDownloaded, mmCoreEventPackageStatusChanged,
mmCoreOutdated, $mmCoursePrefetchDelegate, $mmSite, $mmEvents, $mmaModWikiSync, $mmContentLinkHandlerFactory) {
mmCoreOutdated, $mmCoursePrefetchDelegate, $mmSite, $mmEvents, $mmaModWikiSync, $mmContentLinkHandlerFactory, $mmText) {
var self = {};

/**
Expand Down Expand Up @@ -283,7 +283,7 @@ angular.module('mm.addons.mod_wiki')

var section = "";
if (typeof params.section != 'undefined') {
section = decodeURIComponent(params.section.replace(/\+/g, ' '));
section = $mmText.decodeURIComponent(params.section.replace(/\+/g, ' '));
}

// Return actions.
Expand Down
2 changes: 1 addition & 1 deletion www/core/lib/filepool.js
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ angular.module('mm.core')
filename;

// Decode URL.
url = $mmText.decodeHTML(decodeURIComponent(url));
url = $mmText.decodeHTML($mmText.decodeURIComponent(url));

if (url.indexOf('/webservice/pluginfile') !== -1) {
// Remove attributes that do not matter.
Expand Down
6 changes: 3 additions & 3 deletions www/core/lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ angular.module('mm.core')
* @return {String} The file name normalized.
*/
self.normalizeFileName = function(filename) {
filename = decodeURIComponent(filename);
filename = $mmText.decodeURIComponent(filename);
return filename;
};

Expand Down Expand Up @@ -1246,7 +1246,7 @@ angular.module('mm.core')
number = 1;

// Clean the file name.
fileNameWithoutExtension = $mmText.removeSpecialCharactersForFiles(decodeURIComponent(fileNameWithoutExtension));
fileNameWithoutExtension = $mmText.removeSpecialCharactersForFiles($mmText.decodeURIComponent(fileNameWithoutExtension));

// Index the files by name.
angular.forEach(entries, function(entry) {
Expand Down Expand Up @@ -1276,7 +1276,7 @@ angular.module('mm.core')
}
}).catch(function() {
// Folder doesn't exist, name is unique. Clean it and return it.
return $mmText.removeSpecialCharactersForFiles(decodeURIComponent(fileName));
return $mmText.removeSpecialCharactersForFiles($mmText.decodeURIComponent(fileName));
});
};

Expand Down
38 changes: 37 additions & 1 deletion www/core/lib/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ angular.module('mm.core')
}
}
return false;
}
};

/**
* Strip Unicode long char of a given text.
Expand All @@ -640,5 +640,41 @@ angular.module('mm.core')
return stripped;
};

/**
* Same as Javascript's decodeURI, but if an exception is thrown it will return the original URI.
*
* @module mm.core
* @ngdoc method
* @name $mmText#decodeURI
* @param {String} uri URI to decode.
* @return {String} Decoded URI, or original URI if an exception is thrown.
*/
self.decodeURI = function(uri) {
try {
return decodeURI(uri);
} catch(ex) {
// Error, use the original URI.
}
return uri;
};

/**
* Same as Javascript's decodeURIComponent, but if an exception is thrown it will return the original URI.
*
* @module mm.core
* @ngdoc method
* @name $mmText#decodeURIComponent
* @param {String} uri URI to decode.
* @return {String} Decoded URI, or original URI if an exception is thrown.
*/
self.decodeURIComponent = function(uri) {
try {
return decodeURIComponent(uri);
} catch(ex) {
// Error, use the original URI.
}
return uri;
};

return self;
});
8 changes: 4 additions & 4 deletions www/core/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ angular.module('mm.core')
// with white spaces, special characters...
if (path.indexOf(fsRoot > -1)) {
path = path.replace(fsRoot, "");
path = encodeURIComponent(decodeURIComponent(path));
path = encodeURIComponent($mmText.decodeURIComponent(path));
path = fsRoot + path;
}

Expand Down Expand Up @@ -1468,14 +1468,14 @@ angular.module('mm.core')
// Treat elements with src (img, audio, video, ...).
media = div[0].querySelectorAll('img, video, audio, source, track');
angular.forEach(media, function(el) {
var src = paths[decodeURIComponent(el.getAttribute('src'))];
var src = paths[$mmText.decodeURIComponent(el.getAttribute('src'))];
if (typeof src !== 'undefined') {
el.setAttribute('src', src);
}

// Treat video posters.
if (el.tagName == 'VIDEO' && el.getAttribute('poster')) {
src = paths[decodeURIComponent(el.getAttribute('poster'))];
src = paths[$mmText.decodeURIComponent(el.getAttribute('poster'))];
if (typeof src !== 'undefined') {
el.setAttribute('poster', src);
}
Expand All @@ -1484,7 +1484,7 @@ angular.module('mm.core')

// We do the same for links.
angular.forEach(div.find('a'), function(anchor) {
var href = decodeURIComponent(anchor.getAttribute('href')),
var href = $mmText.decodeURIComponent(anchor.getAttribute('href')),
url = paths[href];

if (typeof url !== 'undefined') {
Expand Down