roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adityasha...@apache.org
Subject [roller] 01/03: Fixed: Variables scoping in ajax-user.js (ROL-2157) Pattern is identified and reported at sonacloud.io as Blocker
Date Sun, 03 Nov 2019 13:20:40 GMT
This is an automated email from the ASF dual-hosted git repository.

adityasharma pushed a commit to branch ROL-2157
in repository https://gitbox.apache.org/repos/asf/roller.git

commit a541cc0dcf238e0168111f598a22f5dcbce36086
Author: Aditya Sharma <iamadityasharma7@gmail.com>
AuthorDate: Sun Nov 3 18:16:41 2019 +0530

    Fixed: Variables scoping in ajax-user.js (ROL-2157)
    Pattern is identified and reported at  sonacloud.io as Blocker
    
    JavaScript variable scope can be particularly difficult to understand and get right. The
situation gets even worse when you consider the accidental creation of global variables, which
is what happens when you declare a variable inside a function or the for clause of a for-loop
without using the let, const or var keywords.
---
 .../webapp/WEB-INF/jsps/editor/MembersInvite.jsp   | 22 +++++++-------
 app/src/main/webapp/roller-ui/scripts/ajax-user.js | 34 +++++++++++-----------
 2 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/app/src/main/webapp/WEB-INF/jsps/editor/MembersInvite.jsp b/app/src/main/webapp/WEB-INF/jsps/editor/MembersInvite.jsp
index 0f3aabe..f285705 100644
--- a/app/src/main/webapp/WEB-INF/jsps/editor/MembersInvite.jsp
+++ b/app/src/main/webapp/WEB-INF/jsps/editor/MembersInvite.jsp
@@ -23,12 +23,12 @@
 <s:form action="invite!save" cssClass="form-horizontal">
 	<s:hidden name="salt" />
     <s:hidden name="weblog" value="%{actionWeblog.handle}" />
-    
+
     <div class="formrow">
        <label for="userName" class="formrow">
            <s:text name="inviteMember.userName" /></label>
        <div>
-           <input name="userName" id="userName" size="30" maxlength="30" 
+           <input name="userName" id="userName" size="30" maxlength="30"
                onfocus="onMemberNameFocus(true)" onkeyup="onMemberNameChange(true)" /><br
/>
        </div>
     </div>
@@ -38,8 +38,8 @@
        <div>
            <select id="userList" size="10" onchange="onMemberSelected()" style="width:400px"></select>
        </div>
-    </div>    
-    
+    </div>
+
     <div style="clear:left">
        <label for="userName" class="formrow" />
            <s:text name="inviteMember.permissions" /></label>
@@ -49,9 +49,9 @@
        <s:text name="inviteMember.author" />
        <input type="radio" name="permissionString" value="edit_draft" />
        <s:text name="inviteMember.limited" />
-    </div>  
-         
-    <br />      
+    </div>
+
+    <br />
     <s:submit id="inviteButton" value="%{getText('inviteMember.button.save')}"  cssClass="btn
btn-default"/>
     <s:submit value="%{getText('generic.cancel')}" action="invite!cancel" cssClass="btn"/>
 
@@ -67,12 +67,12 @@
     });
 
     function onMemberNameChange(enabled) {
-        u = userURL;
+        var u = userURL;
         if (enabled != null) {
             u = u + "&enabled=" + enabled;
         }
 
-        userName = $('#userName').val();
+        var userName = $('#userName').val();
         if (userName.length > 0) {
             u = u + "&startsWith=" + userName;
         }
@@ -81,7 +81,7 @@
     }
 
     function onMemberSelected() {
-        userName = $('#userList').children("option:selected").val();
+        var userName = $('#userList').children("option:selected").val();
         if (userName !== '') {
             $('#inviteButton').attr("disabled", false);
         }
@@ -90,7 +90,7 @@
     function onMemberNameFocus(enabled) {
         if (!init) {
             init = true;
-            u = userURL;
+            var u = userURL;
 
             if (enabled != null) {
                 u = u + "&enabled=" + enabled;
diff --git a/app/src/main/webapp/roller-ui/scripts/ajax-user.js b/app/src/main/webapp/roller-ui/scripts/ajax-user.js
index f3bbfb2..49715b3 100644
--- a/app/src/main/webapp/roller-ui/scripts/ajax-user.js
+++ b/app/src/main/webapp/roller-ui/scripts/ajax-user.js
@@ -37,30 +37,30 @@ var userURL = "<%= request.getContextPath() %>" + "/roller-ui/authoring/userdata
 function onUserNameFocus(enabled) {
     if (!init) {
         init = true;
-        u = userURL;
+        var u = userURL;
         if (enabled != null) u = u + "&enabled=" + enabled;
         sendUserRequest(u);
     } else {
-        userSubmitButton = document.getElementById("user-submit");
+        var userSubmitButton = document.getElementById("user-submit");
         userSubmitButton.disabled = true;
     }
 }
 
 function onUserNameChange(enabled) {
-    u = userURL;
+    var u = userURL;
     if (enabled != null) u = u + "&enabled=" + enabled;
-    userName = document.getElementById("userName");
+    var userName = document.getElementById("userName");
     if (userName.value.length > 0) u = u + "&startsWith=" + userName.value;
     sendUserRequest(u);
 }
 
 function onUserSelected() {
-    userList = document.getElementById("userList");
-    user = userList.options[userList.options.selectedIndex];
-    userName = document.getElementById("userName");
+    var userList = document.getElementById("userList");
+    var user = userList.options[userList.options.selectedIndex];
+    var userName = document.getElementById("userName");
     userName.value = user.value;
 
-    userSubmitButton = document.getElementById("user-submit");
+    var userSubmitButton = document.getElementById("user-submit");
     userSubmitButton.disabled = false;
 }
 
@@ -74,21 +74,21 @@ function sendUserRequest(url) {
 
 function handleUserResponse() {
     if (http.readyState === 4) {
-        userList = document.getElementById("userList");
-        for (i = userList.options.length; i >= 0; i--) {
+        var userList = document.getElementById("userList");
+        for (var i = userList.options.length; i >= 0; i--) {
             userList.options[i] = null;
-        }   
-        data = http.responseText;
+        }
+        var data = http.responseText;
         if (data.indexOf("\n") !== -1) {
-            lines = data.split('\n');
-            for (i = 0; i < lines.length; i++) {
+            var lines = data.split('\n');
+            for (var i = 0; i < lines.length; i++) {
                 if (lines[i].indexOf(',') !== -1) {
-                   userArray = lines[i].split(',');
-                   userList.options[userList.length] = 
+                   var userArray = lines[i].split(',');
+                   userList.options[userList.length] =
                       new Option(userArray[0] + " (" + userArray[1] + ")", userArray[0]);
                 }
             }
-        }  
+        }
 
     }
     isBusy = false;


Mime
View raw message