From c7134bc4947bde7f52d58ec10be8bd15c49c9313 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 4 May 2018 21:39:39 -0400 Subject: [PATCH] #553 implemented. catch variables are no longer false flags --- src/main/java/com/cflint/CFLint.java | 13 +++++++++++++ .../com/cflint/tests/VarScoper/553_catch.cfc | 14 ++++++++++++++ .../cflint/tests/VarScoper/553_catch.expected.txt | 11 +++++++++++ .../com/cflint/tests/VarScoper/553_cfml_catch.cfc | 9 +++++++++ .../tests/VarScoper/553_cfml_catch.expected.txt | 11 +++++++++++ 5 files changed, 58 insertions(+) create mode 100644 src/test/resources/com/cflint/tests/VarScoper/553_catch.cfc create mode 100644 src/test/resources/com/cflint/tests/VarScoper/553_catch.expected.txt create mode 100644 src/test/resources/com/cflint/tests/VarScoper/553_cfml_catch.cfc create mode 100644 src/test/resources/com/cflint/tests/VarScoper/553_cfml_catch.expected.txt diff --git a/src/main/java/com/cflint/CFLint.java b/src/main/java/com/cflint/CFLint.java index dc78ab1a1..328391e15 100644 --- a/src/main/java/com/cflint/CFLint.java +++ b/src/main/java/com/cflint/CFLint.java @@ -609,6 +609,14 @@ private void process(final Element elem, final String space, final Context conte scanElement(elem, context); processStack(elem.getChildElements(), space + " ", context); handler.pop(); + } else if (elem.getName().equalsIgnoreCase(CF.CFCATCH)) { + scanElement(elem, context); + handler.push(CF.CFCATCH); + if(elem.getAttributeValue("name")!=null){ + handler.addVariable(elem.getAttributeValue("name")); + } + processStack(elem.getChildElements(), space + " ", context); + handler.pop(); } else { scanElement(elem, context); for (final Entry expression : unpackTagExpressions(elem).entrySet()) { @@ -875,7 +883,12 @@ private void process(final CFScriptStatement expression, final Context context) final CFTryCatchStatement cftry = (CFTryCatchStatement) expression; process(cftry.getBody(), context); for (final CFCatchStatement stmt : cftry.getCatchStatements()) { + handler.push(CF.CFCATCH); + if(stmt.getVariable()!=null){ + handler.addVariable(stmt.getVariable().getName()); + } process(stmt.getCatchBody(), context); + handler.pop(); } process(cftry.getFinallyStatement(), context); } else if (expression instanceof CFReturnStatement) { diff --git a/src/test/resources/com/cflint/tests/VarScoper/553_catch.cfc b/src/test/resources/com/cflint/tests/VarScoper/553_catch.cfc new file mode 100644 index 000000000..5b4ac84cc --- /dev/null +++ b/src/test/resources/com/cflint/tests/VarScoper/553_catch.cfc @@ -0,0 +1,14 @@ +component { + public string function renderPage( required any page, required any docTree, required boolean edit ){ + try { + var renderedPage = renderTemplate( + template = "templates/#_getPageLayoutFile( arguments.page )#.cfm" + , args = { page = arguments.page, docTree=arguments.docTree, edit=edit } + , helpers = "/builders/html/helpers" + ); + } catch( any e ) { + e.additional.luceeDocsPageId = arguments.page.getid(); + rethrow; + } + } +} \ No newline at end of file diff --git a/src/test/resources/com/cflint/tests/VarScoper/553_catch.expected.txt b/src/test/resources/com/cflint/tests/VarScoper/553_catch.expected.txt new file mode 100644 index 000000000..b2d59ba55 --- /dev/null +++ b/src/test/resources/com/cflint/tests/VarScoper/553_catch.expected.txt @@ -0,0 +1,11 @@ +{ + "version" : "", + "timestamp" : 1513437208, + "issues" : [ ], + "counts" : { + "totalFiles" : 0, + "totalLines" : 0, + "countByCode" : [ ], + "countBySeverity" : [ ] + } +} \ No newline at end of file diff --git a/src/test/resources/com/cflint/tests/VarScoper/553_cfml_catch.cfc b/src/test/resources/com/cflint/tests/VarScoper/553_cfml_catch.cfc new file mode 100644 index 000000000..7ea2d8775 --- /dev/null +++ b/src/test/resources/com/cflint/tests/VarScoper/553_cfml_catch.cfc @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/com/cflint/tests/VarScoper/553_cfml_catch.expected.txt b/src/test/resources/com/cflint/tests/VarScoper/553_cfml_catch.expected.txt new file mode 100644 index 000000000..30fd1061b --- /dev/null +++ b/src/test/resources/com/cflint/tests/VarScoper/553_cfml_catch.expected.txt @@ -0,0 +1,11 @@ +{ + "version" : "", + "timestamp" : 1525483036, + "issues" : [ ], + "counts" : { + "totalFiles" : 0, + "totalLines" : 0, + "countByCode" : [ ], + "countBySeverity" : [ ] + } +} \ No newline at end of file