From b7091f020dbacf47bd40c02230a3bcc9995acd51 Mon Sep 17 00:00:00 2001 From: KamasamaK Date: Wed, 20 Dec 2017 10:35:40 -0500 Subject: [PATCH] Added more tags and attributes to check in VarScoper (#495) * Added more tags and attributes to check in VarScoper * Corrected tests --- src/main/java/com/cflint/CF.java | 33 +++++++++++++++++-- .../com/cflint/plugins/core/VarScoper.java | 29 +++++++++------- .../cflint/TestCFBugs_VarScoper_Names.java | 10 +++--- .../cflint/TestCFBugs_VarScoper_TagAttr.java | 27 +++++++++------ .../VarScoper/cfloop_index_413.expected.txt | 4 +-- 5 files changed, 74 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/cflint/CF.java b/src/main/java/com/cflint/CF.java index 254653483..284046bf0 100644 --- a/src/main/java/com/cflint/CF.java +++ b/src/main/java/com/cflint/CF.java @@ -16,6 +16,11 @@ public class CF { */ public static final String CFCATCH = "cfcatch"; + /** + * CFChart tag. + */ + public static final String CFCHART = "cfchart"; + /** * CFCollection tag. */ @@ -90,6 +95,11 @@ public class CF { */ public static final String CFFUNCTION = "cffunction"; + /** + * CFHTMLToPDF Tag. + */ + public static final String CFHTMLTOPDF = "cfhtmltopdf"; + /** * CFHTTP Tag. */ @@ -100,6 +110,16 @@ public class CF { */ public static final String CFIF = "cfif"; + /** + * CFImage Tag. + */ + public static final String CFIMAGE = "cfimage"; + + /** + * CFIMAP Tag. + */ + public static final String CFIMAP = "cfimap"; + /** * CFInclude Tag. */ @@ -210,6 +230,16 @@ public class CF { */ public static final String CFSETTING = "cfsetting"; + /** + * CFSharepoint Tag. + */ + public static final String CFSHAREPOINT = "cfsharepoint"; + + /** + * CFSpreadsheet Tag. + */ + public static final String CFSPREADSHEET = "cfspreadsheet"; + /** * CFStoredProc Tag. */ @@ -260,7 +290,6 @@ public class CF { */ public static final String STRUCT = "struct"; - /** * CFScript dbtype. */ @@ -401,7 +430,7 @@ public class CF { * CF scope variables. */ public static final String VARIABLES = "variables"; - + /** * CF scope local. */ diff --git a/src/main/java/com/cflint/plugins/core/VarScoper.java b/src/main/java/com/cflint/plugins/core/VarScoper.java index 5d26aa927..9cb321f87 100644 --- a/src/main/java/com/cflint/plugins/core/VarScoper.java +++ b/src/main/java/com/cflint/plugins/core/VarScoper.java @@ -22,11 +22,13 @@ public class VarScoper extends CFLintScannerAdapter { public static final String VARIABLE = "variable"; public static final String RESULT = "result"; + public static final String STRUCTNAME = "structname"; private final Map> checkElementAttributes = new HashMap<>(); - private final List checkNames = Arrays.asList(CF.CFQUERY, CF.CFSTOREDPROC, CF.CFFEED, CF.CFDIRECTORY, + private final List checkNames = Arrays.asList(CF.CFQUERY, CF.CFFEED, CF.CFDIRECTORY, CF.CFFORM, CF.CFFTP, CF.CFOBJECT, CF.CFSEARCH, CF.CFPROCRESULT, CF.CFPOP, CF.CFREGISTRY, CF.CFREPORT, - CF.CFDBINFO, CF.CFDOCUMENT, CF.CFCOLLECTION, CF.CFPDF, CF.CFZIP, CF.CFLDAP); + CF.CFDBINFO, CF.CFDOCUMENT, CF.CFCOLLECTION, CF.CFPDF, CF.CFZIP, CF.CFLDAP, CF.CFHTTP, CF.CFCHART, + CF.CFHTMLTOPDF, CF.CFIMAGE, CF.CFIMAP, CF.CFSHAREPOINT, CF.CFSPREADSHEET); private final Collection scopes = Arrays.asList(CF.APPLICATION, CF.CGI, CF.COOKIE, CF.FORM, CF.REQUEST, CF.SERVER, CF.SESSION, CF.URL); @@ -60,19 +62,24 @@ public void expression(final CFScriptStatement expression, final Context context } public VarScoper() { - // checkElementAttributes.put(CF.CFLOOP, Arrays.asList(CF.index, CF.ITEM)); - checkElementAttributes.put(CF.CFINVOKE, Arrays.asList(CF.RETURNVARIABLE)); - checkElementAttributes.put(CF.CFFILE, Arrays.asList(VARIABLE)); - checkElementAttributes.put(CF.CFSAVECONTENT, Arrays.asList(VARIABLE)); + checkElementAttributes.put(CF.CFEXECUTE, Arrays.asList(VARIABLE)); + checkElementAttributes.put(CF.CFFEED, Arrays.asList(CF.QUERY)); + checkElementAttributes.put(CF.CFFILE, Arrays.asList(VARIABLE, RESULT)); + checkElementAttributes.put(CF.CFFTP, Arrays.asList(RESULT)); checkElementAttributes.put(CF.CFHTTP, Arrays.asList(RESULT)); + checkElementAttributes.put(CF.CFIMAGE, Arrays.asList(STRUCTNAME)); + checkElementAttributes.put(CF.CFINVOKE, Arrays.asList(CF.RETURNVARIABLE)); + checkElementAttributes.put(CF.CFLOOP, Arrays.asList(CF.INDEX, CF.ITEM)); + checkElementAttributes.put(CF.CFNTAUTHENTICATE, Arrays.asList(RESULT)); + checkElementAttributes.put(CF.CFPROCPARAM, Arrays.asList(VARIABLE)); checkElementAttributes.put(CF.CFQUERY, Arrays.asList(RESULT)); - checkElementAttributes.put(CF.CFMAIL, Arrays.asList(CF.QUERY)); - checkElementAttributes.put(CF.CFFTP, Arrays.asList(RESULT)); + checkElementAttributes.put(CF.CFREGISTRY, Arrays.asList(VARIABLE)); + checkElementAttributes.put(CF.CFSAVECONTENT, Arrays.asList(VARIABLE)); + checkElementAttributes.put(CF.CFSPREADSHEET, Arrays.asList(CF.QUERY)); + checkElementAttributes.put(CF.CFSTOREDPROC, Arrays.asList(RESULT)); checkElementAttributes.put(CF.CFWDDX, Arrays.asList(CF.OUTPUT)); - checkElementAttributes.put(CF.CFEXECUTE, Arrays.asList(VARIABLE)); - checkElementAttributes.put(CF.CFNTAUTHENTICATE, Arrays.asList(RESULT)); checkElementAttributes.put(CF.CFXML, Arrays.asList(VARIABLE)); - + checkElementAttributes.put(CF.CFZIP, Arrays.asList(VARIABLE)); } @Override diff --git a/src/test/java/com/cflint/TestCFBugs_VarScoper_Names.java b/src/test/java/com/cflint/TestCFBugs_VarScoper_Names.java index f6c02bf75..bc4d93691 100644 --- a/src/test/java/com/cflint/TestCFBugs_VarScoper_Names.java +++ b/src/test/java/com/cflint/TestCFBugs_VarScoper_Names.java @@ -1,9 +1,9 @@ package com.cflint; /** - * tests from + * tests from * https://github.com/mschierberl/varscoper/blob/master/varScoper.cfc - * + * */ import static org.junit.Assert.assertEquals; @@ -37,12 +37,14 @@ public void setUp() throws CFLintConfigurationException { @Parameterized.Parameters(name = "{0}") public static Collection primeNumbers() { return Arrays.asList( - new String[][] { new String[] { "CFStoredProc" }, new String[] { "CFQuery" }, new String[] { "CFFeed" }, + new String[][] { new String[] { "CFQuery" }, new String[] { "CFFeed" }, new String[] { "CFHttp" }, new String[] { "CFDirectory" }, new String[] { "CFForm" }, new String[] { "CFFtp" }, new String[] { "CFObject" }, new String[] { "CFSearch" }, new String[] { "CFProcResult" }, new String[] { "CFPop" }, new String[] { "CFRegistry" }, new String[] { "CFReport" }, new String[] { "CFDBInfo" }, new String[] { "CFDocument" }, new String[] { "CFCollection" }, - new String[] { "CFPdf" }, new String[] { "CFZip" }, new String[] { "CFLdap" } }); + new String[] { "CFPdf" }, new String[] { "CFZip" }, new String[] { "CFLdap" }, + new String[] { "CFChart" }, new String[] { "CFHtmlToPdf" }, new String[] { "CFImage" }, + new String[] { "CFImap" }, new String[] { "CFSharepoint" }, new String[] { "CFSpreadsheet" } }); } public TestCFBugs_VarScoper_Names(final String tagName) { diff --git a/src/test/java/com/cflint/TestCFBugs_VarScoper_TagAttr.java b/src/test/java/com/cflint/TestCFBugs_VarScoper_TagAttr.java index 70c92b273..2cbdfe65e 100644 --- a/src/test/java/com/cflint/TestCFBugs_VarScoper_TagAttr.java +++ b/src/test/java/com/cflint/TestCFBugs_VarScoper_TagAttr.java @@ -1,9 +1,9 @@ package com.cflint; /** - * tests from + * tests from * https://github.com/mschierberl/varscoper/blob/master/varScoper.cfc - * + * */ import static org.junit.Assert.assertEquals; @@ -39,19 +39,26 @@ public void setUp() throws CFLintConfigurationException { @Parameterized.Parameters(name = "{0}") public static Collection primeNumbers() { List retval = new ArrayList(); - // retval.add(new String[] { "CFLoop", "Index" }); - // retval.add(new String[] { "CFLoop", "Item" }); - retval.add(new String[] { "CFInvoke", "ReturnVariable" }); + retval.add(new String[] { "CFExecute", "Variable" }); + retval.add(new String[] { "CFFeed", "Query" }); retval.add(new String[] { "CFFile", "Variable" }); - retval.add(new String[] { "CFSavecontent", "Variable" }); + retval.add(new String[] { "CFFile", "Result" }); + retval.add(new String[] { "CFFtp", "Result" }); retval.add(new String[] { "CFHttp", "Result" }); + retval.add(new String[] { "CFImage", "StructName" }); + retval.add(new String[] { "CFInvoke", "ReturnVariable" }); + retval.add(new String[] { "CFLoop", "Index" }); + retval.add(new String[] { "CFLoop", "Item" }); + retval.add(new String[] { "CFNtAuthenticate", "Result" }); + retval.add(new String[] { "CFProcParam", "Variable" }); retval.add(new String[] { "CFQuery", "Result" }); - retval.add(new String[] { "CFMail", "Query" }); - retval.add(new String[] { "CFFtp", "Result" }); + retval.add(new String[] { "CFRegistry", "Variable" }); + retval.add(new String[] { "CFSavecontent", "Variable" }); + retval.add(new String[] { "CFSpreadsheet", "Query" }); + retval.add(new String[] { "CFStoredProc", "Result" }); retval.add(new String[] { "CFWddx", "Output" }); - retval.add(new String[] { "CFExecute", "Variable" }); - retval.add(new String[] { "CFNtAuthenticate", "Result" }); retval.add(new String[] { "CFXml", "Variable" }); + retval.add(new String[] { "CFZip", "Variable" }); return retval; } diff --git a/src/test/resources/com/cflint/tests/VarScoper/cfloop_index_413.expected.txt b/src/test/resources/com/cflint/tests/VarScoper/cfloop_index_413.expected.txt index a5b2ed3ba..72fa5bec3 100644 --- a/src/test/resources/com/cflint/tests/VarScoper/cfloop_index_413.expected.txt +++ b/src/test/resources/com/cflint/tests/VarScoper/cfloop_index_413.expected.txt @@ -11,11 +11,11 @@ "file" : "src\\test\\resources\\com\\cflint\\tests\\VarScoper\\cfloop_index_413.cfc", "fileName" : "cfloop_index_413.cfc", "function" : "foo", - "column" : 2, + "column" : 33, "line" : 2, "message" : "Variable idx is not declared with a var statement.", "variable" : "idx", - "expression" : "idx" + "expression" : "\r\n\t\t\r\n\t" } ] }, { "severity" : "ERROR",