Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
0c7620a5
Commit
0c7620a5
authored
Jan 20, 2015
by
Xavier Antoviaque
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6637 from open-craft/mtyaka/validate-chars
Improve JS course key validation to not allow special chars.
parents
957e0e28
d8e07656
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
1 deletions
+49
-1
cms/static/js/spec/views/utils/view_utils_spec.js
+48
-0
cms/static/js/views/utils/view_utils.js
+1
-1
No files found.
cms/static/js/spec/views/utils/view_utils_spec.js
View file @
0c7620a5
...
...
@@ -40,5 +40,53 @@ define(["jquery", "underscore", "js/views/baseview", "js/views/utils/view_utils"
ViewHelpers
.
verifyNotificationShowing
(
notificationSpy
,
/Testing/
);
});
});
describe
(
"course/library fields validation"
,
function
()
{
describe
(
"without unicode support"
,
function
()
{
it
(
"validates presence of field"
,
function
()
{
var
error
=
ViewUtils
.
validateURLItemEncoding
(
''
,
false
);
expect
(
error
).
toBeTruthy
();
});
it
(
"checks for presence of special characters in the field"
,
function
()
{
var
error
;
// Special characters are not allowed.
error
=
ViewUtils
.
validateURLItemEncoding
(
'my+field'
,
false
);
expect
(
error
).
toBeTruthy
();
error
=
ViewUtils
.
validateURLItemEncoding
(
'2014!'
,
false
);
expect
(
error
).
toBeTruthy
();
error
=
ViewUtils
.
validateURLItemEncoding
(
'*field*'
,
false
);
expect
(
error
).
toBeTruthy
();
// Spaces not allowed.
error
=
ViewUtils
.
validateURLItemEncoding
(
'Jan 2014'
,
false
);
expect
(
error
).
toBeTruthy
();
// -_~. are allowed.
error
=
ViewUtils
.
validateURLItemEncoding
(
'2015-Math_X1.0~'
,
false
);
expect
(
error
).
toBeFalsy
();
});
it
(
"does not allow unicode characters"
,
function
()
{
var
error
=
ViewUtils
.
validateURLItemEncoding
(
'Field-
\
u010d'
,
false
);
expect
(
error
).
toBeTruthy
();
});
});
describe
(
"with unicode support"
,
function
()
{
it
(
"validates presence of field"
,
function
()
{
var
error
=
ViewUtils
.
validateURLItemEncoding
(
''
,
true
);
expect
(
error
).
toBeTruthy
();
});
it
(
"checks for presence of spaces"
,
function
()
{
var
error
=
ViewUtils
.
validateURLItemEncoding
(
'My Field'
,
true
);
expect
(
error
).
toBeTruthy
();
});
it
(
"allows unicode characters"
,
function
()
{
var
error
=
ViewUtils
.
validateURLItemEncoding
(
'Field-
\
u010d'
,
true
);
expect
(
error
).
toBeFalsy
();
});
});
});
});
});
cms/static/js/views/utils/view_utils.js
View file @
0c7620a5
...
...
@@ -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.'
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment