Skip to content

Commit

Permalink
#359 - single quotes fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
ryaneberly committed Jul 22, 2017
1 parent 7877e40 commit e83fd0c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/main/java/com/cflint/CFLint.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.cflint.config.*;
import org.antlr.runtime.BitSet;
import org.antlr.v4.runtime.ANTLRErrorListener;
import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.Recognizer;
import org.antlr.v4.runtime.Token;
Expand Down Expand Up @@ -78,6 +79,7 @@
import cfml.parsing.cfscript.script.CFScriptStatement;
import cfml.parsing.cfscript.script.CFSwitchStatement;
import cfml.parsing.cfscript.script.CFTryCatchStatement;
import cfml.parsing.reporting.ArrayErrorListener;
import cfml.parsing.reporting.IErrorReporter;
import cfml.parsing.reporting.ParseException;
import net.htmlparser.jericho.Attribute;
Expand Down Expand Up @@ -532,17 +534,25 @@ private List<CFExpression> unpackTagExpressions(final Element elem) {
for (Attribute attr : elem.getAttributes()) {
if (attr.getValue() != null && attr.getValue().contains("#") && !attr.getValue().startsWith("'")
&& !attr.getValue().startsWith("\"")) {
//Try wrapping the expression in single or double quotes for parsing.
List<String> literalChar = attr.getValue().contains("'")?Arrays.asList("\"","'"):Arrays.asList("'","\"");
try {
final CFExpression exp = cfmlParser.parseCFExpression("\"" + attr.getValue() + "\"", this);
expressions.add(exp);
} catch (Exception e) {
// Try single quotes before reporting a failure
try {
final CFExpression exp = cfmlParser.parseCFExpression("'" + attr.getValue() + "'", this);

List<String> errors = new ArrayList<String>();
ANTLRErrorListener errorReporter = new ArrayErrorListener(errors );
final CFExpression exp = cfmlParser.parseCFExpression(literalChar.get(0) + attr.getValue() + literalChar.get(0), errorReporter);
if(errors.size()==0){
expressions.add(exp);
} catch (Exception e2) {
System.err.println("Error in parsing : " + attr.getValue() + " on tag " + elem.getName());
continue;
}
} catch (Exception e) {
}
// Try other quotes before reporting a failure
try {
final CFExpression exp = cfmlParser.parseCFExpression(literalChar.get(1) + attr.getValue() + literalChar.get(1), this);
expressions.add(exp);
} catch (Exception e2) {
System.err.println("Error in parsing : " + attr.getValue() + " on tag " + elem.getName());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<cfcomponent>
<cffunction name="foo">
<cffile action="write" file="#LCase(local.destination)##rc.attachment_cvhtml_filename#.html" charset="utf-8" output='<!DOCTYPE html><html lang="en"><head><meta charset="utf-8" /></head><body>#local.stepCV#</body>'>
</cffunction>
</cfcomponent>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[ {
"totalfiles" : 0
}, {
"totalsize" : 0
} ]

0 comments on commit e83fd0c

Please sign in to comment.