Improve JS course key validation to not allow special chars.

Course and Library keys cannot contiain !'()* special characters,
but the JS validation on the new course/library failed to detect
these characters.

`encodeURIComponent` is used to check the string for special characters,
but `encodeURIComponent` does not encode these characters: -_!~*'().
(see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)

The -_~ characters are allowed in course keys, but !'()* are not,
so add an explicit check for these characters to make sure a field
containing these characters does not pass the validation.
This commit is contained in:
Matjaz Gregoric
2015-01-08 10:38:40 +01:00
parent 477031e171
commit d8e076566d
2 changed files with 49 additions and 1 deletions

View File

@@ -199,7 +199,7 @@ define(["jquery", "underscore", "gettext", "js/views/feedback_notification", "js
}
}
else {
if (item !== encodeURIComponent(item)) {
if (item !== encodeURIComponent(item) || item.match(/[!'()*]/)) {
return gettext('Please do not use any spaces or special characters in this field.');
}
}