Skip to content

Commit c533a0f

Browse files
soerenmaucheradminniamccash
authored
Add column type check: For loop iterators "i" should be declared (#94)
* Add Column Type Check: For loop iterators "i" should be declared * Update README.md Added description for new Column Type Check --------- Co-authored-by: admin <[email protected]> Co-authored-by: niamccash <[email protected]>
1 parent e282fc7 commit c533a0f

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ The "glide.invalid_query.returns_no_rows" property provides a safeguard against
256256
### Use GlideRecordSecure instead of GlideRecord API for Client Callable Script Include
257257
Use GlideRecordSecure API to ensure the security checks are performed and unauthorized access of data is prevented as it will automatically enforce ACLs.
258258

259+
### For loop iterators "i" should be declared
260+
In general, variables in JavaScript should be properly declared (e.g. using “var”). The declaration defines the scope of the variable, ensuring it's accessible only within the intended block. This prevents unintended variable pollution and conflicts. Especially in for loops, often an iterator “i” is used and not properly declared. For example “for (i=0; i<10; i++)” instead of “for (var i=0; i<10; i++)”. As a result, this could unintentionally alter the value of other 'i' iterators in different for loops.
261+
259262
## Category: User Experience
260263

261264
### Added a Number Prefix which already exists
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
us24VYwzDRWhd4Oah1VDlP_Gi4_4M9btMV4eKYPBm8Zzc5LaRJUAxHANj7wFAl6t57zgJ_lTtkOUFkFVYMcCjHvli38HPThQ3BmHXwvVFRmHpRPOZZvjmuzxlyH07Mn4mno2LWxtQ7ndCMMnos7H7PqTryMbkNY5-I4kaudTZRcnVMRYXeBAjt0rmsycqK4CxWDQ191IKlHMrCTKXowvpYWfPzh2czKYc8V9KE7ThxisuEYXUEpnOp_n73KAqqpdMdo0WvugM451Xp8hSNpOziQLVxGiQ20jNQcEU1_Q-4Ic-Kq2CHZb_BHaLPKPttxvwUqHtoTDE6o84VW7BtvYMKbhdWRdnv9mVBGw9O_xT001SB8ZnRHW_wl8pst-oMsR3Sr8oKfrUfE3mXUSF3dfj4U6wwUj9TSJ-OC0nYg0_EzeaNq_9ZrQHd87kvKnkB1wkq_C3OYrC6ojWRoiEZUcyox4DRRkub7hCYIoRvynx0uL6x1DM-ZxR3cwtzZYNv3eSTVB55mtWnD8jz0RQ8RZYNwkoNJE22J6cBG3FsL9SYtU6brPGg7Ln6tbRTfGIBL5EynQII5ZCVo0-geMItmYfGLc4vCZbeI_FuDQJmvhWgX0OaMWwJO3aSzO4rQ0RQH8zidCOOybwX4F6ThDnM9uDqjC1LgME_ZpthcJPKl9sWk
1+
hnVNxV4rfot4d9roIUiS1y8MiA6yW2TLoj_BuFZOUy7py4ZNF7-guTFSSNrSBpePiCWClCEpw9oJcr73m6lFrAd1WDdPiD9OxH08pLKpwR5ONIH1rGEccNmFbv9g0Tl6WjP-bvv4Hc58KbBZH1W4tL3w96s_ZTOPt3Nte00nJ95ewI8vnUWv4VjaDJ6al8JWIyEuJb5RXLUO0PzqMhD4u0q1Q6HaYcUUSCG1GvRlb_OKOQtN2M2_y6meC3TTzh5VpteL3NIf0QwPAE4XLV1uhLcW_VpO9uKkN9cH8yNSA6tE8tN83lt7k6XRmozR5H0S2LAe-iWkQp2X3n80glIGBkd-RrD--UF5OMyskAC9w9TeftrdgPdjZOscNPUjw4fo0GUUmZFABvJMtZZFX9XYFlM32uNkOmL7KbgsGyNmwJ5r-gmPdi7fn6zjV5CRel62ny5DqnxaOPgKcFZi14Om411pnv33MbxlIb0C9_xmHXLttS2nUO2HfpxEOPH3NbyfI219W_flsKm1McDrScaKiQkmgSpiml8nAIbDG4LAKN_Kc6xyrBXCy1bTyLD9dMrzGg40cTpG2espsWfWSh_LiAJI9Wh4tvR1UEuUcge7PiCrqxMJSAvWVwcS-OQooqNmLx0tC5fsKkof6g3UCOChVDXreeRXNjevNmguCqtW_Tk
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?><record_update table="scan_column_type_check">
2+
<scan_column_type_check action="INSERT_OR_UPDATE">
3+
<active>true</active>
4+
<category>security</category>
5+
<column_type>script</column_type>
6+
<description>Variable declaration defines the scope of the variable, ensuring it's accessible only within the intended block. This prevents unintended variable pollution and conflicts. </description>
7+
<documentation_url>https://www.servicenow.com/community/developer-forum/why-declaration-of-variables-is-essential-in-servicenow/m-p/2379013</documentation_url>
8+
<finding_type>scan_finding</finding_type>
9+
<name>For loop iterators "i" should be declared</name>
10+
<priority>3</priority>
11+
<resolution_details>Rather than using a construction like "for (i=0; i&lt;10; i++)," it's advisable to explicitly declare the iterator "i" within the for loop by using the "var" keyword, like this: "for (var i=0; i&lt;10; i++)". This ensures proper variable scoping and avoids unintended issues in your code.</resolution_details>
12+
<run_condition/>
13+
<score_max>100</score_max>
14+
<score_min>0</score_min>
15+
<score_scale>1</score_scale>
16+
<script><![CDATA[(function(engine) {
17+
var search_regex = /for\s*\(\s*i\s*=\s*[^;]+/;//This regex detects for loops with an uninitialized i iterator.
18+
if (search_regex.test(engine.columnValue)) {
19+
engine.finding.increment();
20+
}
21+
})(engine);]]></script>
22+
<short_description>Declare the iterator "i" in for loops to avoid variable pollution and conflicts</short_description>
23+
<sys_class_name>scan_column_type_check</sys_class_name>
24+
<sys_created_by>admin</sys_created_by>
25+
<sys_created_on>2023-10-14 09:00:00</sys_created_on>
26+
<sys_id>ee62ee7e97b131106c7cfed11153af4f</sys_id>
27+
<sys_mod_count>1</sys_mod_count>
28+
<sys_name>For loop iterators "i" should be declared</sys_name>
29+
<sys_package display_value="Example Instance Checks" source="x_appe_exa_checks">ca8467c41b9abc10ce0f62c3b24bcbaa</sys_package>
30+
<sys_policy/>
31+
<sys_scope display_value="Example Instance Checks">ca8467c41b9abc10ce0f62c3b24bcbaa</sys_scope>
32+
<sys_update_name>scan_column_type_check_ee62ee7e97b131106c7cfed11153af4f</sys_update_name>
33+
<sys_updated_by>admin</sys_updated_by>
34+
<sys_updated_on>2023-10-14 09:05:26</sys_updated_on>
35+
</scan_column_type_check>
36+
<sys_translated_text action="delete_multiple" query="documentkey=ee62ee7e97b131106c7cfed11153af4f"/>
37+
</record_update>

0 commit comments

Comments
 (0)