Skip to content

Commit 78585f1

Browse files
author
jordanmccullough
committed
Refactor query string parsing with regex
Discard fragile substring only extraction with regex to acquire the `teacher` query string value.
1 parent e908ec7 commit 78585f1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

_javascript/curriculum.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ $(function(){
1111

1212
// Parse username from querystring
1313
var urlSearch = window.location.search,
14-
queryString = urlSearch.substring(1,urlSearch.length),
15-
username = queryString.substring((queryString.indexOf("="))+1, queryString.length);
14+
teacherQuery = urlSearch.match(/teacher=[a-z,A-Z,0-9]*/)[0],
15+
username = teacherQuery.substring(8, teacherQuery.length);
16+
1617
if(username){
1718
$.ajax(
1819
{

0 commit comments

Comments
 (0)