Added sanitization of id names

This is a fix for
https://openedx.atlassian.net/browse/TNL-394
escaped all escapable characters in id name strings.
This commit is contained in:
vkaracic
2015-07-06 08:07:49 +00:00
parent f9cb092488
commit 3ec3cf64cc
2 changed files with 13 additions and 1 deletions

View File

@@ -14,6 +14,12 @@ define(['backbone', 'jquery', 'js/staff_debug_actions'],
});
});
describe('sanitize_string', function () {
it('escapes escapable characters in a string', function () {
expect(StaffDebug.sanitized_string('.*+?^:${}()|][')).toBe('\\.\\*\\+\\?\\^\\:\\$\\{\\}\\(\\)\\|\\]\\[');
});
});
describe('get_user', function () {
it('gets the placeholder username if input field is empty', function () {

View File

@@ -11,7 +11,12 @@ var StaffDebug = (function(){
return url;
}
sanitized_string = function(string) {
return string.replace(/[.*+?^:${}()|[\]\\]/g, "\\$&");
}
get_user = function(locname){
locname = sanitized_string(locname);
var uname = $('#sd_fu_' + locname).val();
if (uname==""){
uname = $('#sd_fu_' + locname).attr('placeholder');
@@ -108,7 +113,8 @@ var StaffDebug = (function(){
do_idash_action: do_idash_action,
get_current_url: get_current_url,
get_url: get_url,
get_user: get_user
get_user: get_user,
sanitized_string:sanitized_string
}
})();