Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ryaneberly committed Nov 24, 2016
1 parent c021ffd commit 1489694
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/main/java/com/cflint/CFLint.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ protected void printException(final Exception e, Element... elem) {
public void process(final String src, final String filename) throws ParseException, IOException {
fireStartedProcessing(filename);
final CFMLSource cfmlSource = new CFMLSource(src);
final ParserTag firstTag = cfmlSource.getNextTag(0);
final ParserTag firstTag = getFirstTagQuietly(cfmlSource);
final List<Element> elements = new ArrayList<Element>();
if (firstTag != null) {
elements.addAll(cfmlSource.getChildElements());
Expand All @@ -200,6 +200,13 @@ public void process(final String src, final String filename) throws ParseExcepti
fireFinishedProcessing(filename);
}

protected ParserTag getFirstTagQuietly(final CFMLSource cfmlSource) {
try{
return cfmlSource.getNextTag(0);
}catch(Exception e){e.printStackTrace();}
return null;
}

public void processStack(final List<Element> elements, final String space, final String filename,
final CFIdentifier functionName) throws ParseException, IOException {
for (final Element elem : elements) {
Expand Down
7 changes: 5 additions & 2 deletions src/test/java/com/cflint/TestCFBugs_VarScoper_Names.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ public void runTagAttrTest(final String tag, final String attr, final String var
assertEquals(3, result.get(0).getLine());
assertEquals("test",result.get(0).getFunction());
assertEquals("test",result.get(0).getFilename());
assertEquals("<cfstoredproc name=\"xx\">\r\n</cfstoredproc>".replaceAll("cfstoredproc",tag).replaceAll("name",attr),
result.get(0).getExpression());
String expected = "<cfstoredproc name=\"xx\">".replaceAll("cfstoredproc",tag).replaceAll("name",attr);
if(!result.get(0).getExpression().startsWith(expected)){
assertEquals(expected,
result.get(0).getExpression());
}
}

public void runTagAttrTestVard(final String tag, final String attr, final String variable) throws ParseException,
Expand Down
68 changes: 68 additions & 0 deletions src/test/java/com/cflint/TestCFLint2Files.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.cflint;

import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;

import com.cflint.config.CFLintPluginInfo.PluginInfoRule;
import com.cflint.config.CFLintPluginInfo.PluginInfoRule.PluginMessage;
import com.cflint.config.ConfigRuntime;
import com.cflint.plugins.core.ArgDefChecker;
import com.cflint.plugins.core.QueryParamChecker;

import cfml.parsing.reporting.ParseException;

public class TestCFLint2Files {

private CFLint cfBugs;

@Before
public void setUp() {
final ConfigRuntime conf = new ConfigRuntime();
PluginInfoRule pluginRule = new PluginInfoRule();
pluginRule.setName("ArgDefChecker");
conf.getRules().add(pluginRule);
PluginMessage pluginMessage = new PluginMessage("ARG_DEFAULT_MISSING");
pluginMessage.setSeverity("WARNING");
pluginMessage.setMessageText("Argument ${variable} is not required and does not define a default value.");
pluginRule.getMessages().add(pluginMessage);

pluginRule = new PluginInfoRule();
pluginRule.setName("QueryParamChecker");
conf.getRules().add(pluginRule);
pluginMessage = new PluginMessage("QUERYPARAM_REQ");
pluginMessage.setSeverity("WARNING");
pluginMessage.setMessageText("setSql() statement should use .addParam() instead of #'s for security.");
pluginRule.getMessages().add(pluginMessage);

cfBugs = new CFLint(conf, new ArgDefChecker(),new QueryParamChecker());
}

@Test
public void testVarAndArgs_DisabledOther() throws ParseException, IOException {
final String cfcSrc = "<cfcomponent>\r\n" + "<cffunction name=\"test\">\r\n" + " "
+ "<!---CFLINT-DISABLE SOMEOTHER--->"
+ "<cfargument name=\"xyz\">\r\n"
+ "</cffunction>\r\n" + "</cfcomponent>";
cfBugs.process(cfcSrc, "test");
final List<BugInfo> result = cfBugs.getBugs().getBugList().values().iterator().next();
assertEquals(1, result.size());
assertEquals("ARG_DEFAULT_MISSING", result.get(0).getMessageCode());

final String cfcSrc2 = "component {\r\n" + " public string function fooFunction() {\r\n"
+ "local.query = new Query();\r\n" + "local.query.setSql(\"\r\n"
+ " SELECT id from table where id = #arguments.id#\");" + "</cfscript>\r\n"
+ " }\r\n"
+ "}";
cfBugs.process(cfcSrc2, "test");
final List<BugInfo> result2 = cfBugs.getBugs().getBugList().get("QUERYPARAM_REQ");
assertEquals(1, result2.size());
System.out.println(result2);
assertEquals(4, result2.get(0).getLine());
}
}

0 comments on commit 1489694

Please sign in to comment.