Skip to content

Commit

Permalink
fix #230
Browse files Browse the repository at this point in the history
only show the first parsing error, not the 2nd with line0
  • Loading branch information
ryaneberly committed Jan 6, 2017
1 parent 264077b commit 180ee28
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/cflint/BugInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
public class BugInfo implements Comparable<BugInfo> {

String filename;
int line;
int column;
int line =1; //Default to non-zero task #230
int column=1;
String message;
String messageCode;
String expression;
Expand Down
37 changes: 23 additions & 14 deletions src/main/java/com/cflint/CFLint.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,22 +269,31 @@ private void process(final Element elem, final String space, final Context conte
if (elem.getName().equalsIgnoreCase("cfset") || elem.getName().equalsIgnoreCase("cfif")
|| elem.getName().equalsIgnoreCase("cfelseif") || elem.getName().equalsIgnoreCase("cfreturn")) {
scanElement(elem, context);
final Pattern p = Pattern.compile("<\\w+\\s(.*[^/])/?>", Pattern.MULTILINE | Pattern.DOTALL);
final String expr = elem.getFirstStartTag().toString();
final Matcher m = p.matcher(expr);
if (m.matches()) {
final String cfscript = m.group(1);
try {
final CFExpression expression = cfmlParser.parseCFExpression(cfscript, this);

if (expression == null) {
throw new NullPointerException("expression is null, parsing error");
}
// final Pattern p = Pattern.compile("<\\w+\\s(.*[^/])/?>", Pattern.MULTILINE | Pattern.DOTALL);
// final String expr = elem.getFirstStartTag().toString();
// final Matcher m = p.matcher(expr);
// if (m.matches()) {

// TODO if LUCEE?
final int uglyNotPos = elem.toString().lastIndexOf("<>");
int endPos = elem.getStartTag().getEnd() - 1;

if (uglyNotPos > 0) {
final int nextPos = elem.toString().indexOf(">", uglyNotPos + 2);
if (nextPos > 0 && nextPos < elem.getEndTag().getBegin()) {
endPos = nextPos;
}
}

final String cfscript = elem.toString().substring(elem.getName().length() + 1, endPos);
try {
final CFExpression expression = cfmlParser.parseCFExpression(cfscript, this);
if (expression != null) {
process(expression, elem, context);
} catch (final Exception npe) {
printException(npe, elem);
fireCFLintException(npe, PARSE_ERROR, context.getFilename(), null, null, null, null);
}
} catch (final Exception npe) {
printException(npe, elem);
fireCFLintException(npe, PARSE_ERROR, context.getFilename(), null, null, null, null);
}
processStack(elem.getChildElements(), space + " ", context);

Expand Down
16 changes: 5 additions & 11 deletions src/test/java/com/cflint/TestCFBugs_ParseError.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,13 @@ public void testSimpleCFSET() throws ParseException, IOException{
}

@Test
@Ignore
//Parsing error fixed!
public void testLookBackError() throws ParseException, IOException{
final String cfcSrc = "<cfcomponent>\r\n" +
"<cffunction name=\"test\">\r\n" +
" <cfset var user = userservice[\"getuser\"]();/>\r\n" +
"</cffunction>\r\n" +
"</cfcomponent>";
public void testParseErrorLine1() throws ParseException, IOException{
final String cfcSrc = "<cfif \"foo\" ==== \"bar\">Foo</cfif>";
cfBugs.process(cfcSrc,"test");
List<BugInfo> result = cfBugs.getBugs().getFlatBugList();
System.out.println(result.get(0));
assertEquals(1,result.size());
System.out.println(result.toString());
assertEquals(result.toString(),1,result.size());
assertEquals("PARSE_ERROR",result.get(0).getMessageCode());
assertEquals(3,result.get(0).getLine());
assertEquals(1,result.get(0).getLine());
}
}

0 comments on commit 180ee28

Please sign in to comment.