Skip to content

Commit

Permalink
#518 explicitly override the cfdictionary for cfcookie/@name.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryaneberly committed Jan 1, 2018
1 parent 184aa39 commit 10a892c
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 106 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/cflint/CF.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ public class CF {
* CFProcParam Tag.
*/
public static final String CFPROCPARAM = "cfprocparam";
/**
* CFProcParam Tag.
*/
public static final String CFCOOKIE = "cfcookie";

/**
* CFProcResult Tag.
Expand Down
215 changes: 109 additions & 106 deletions src/main/java/com/cflint/tools/CFMLTagInfo.java
Original file line number Diff line number Diff line change
@@ -1,106 +1,109 @@
package com.cflint.tools;

import cfml.dictionary.Parameter;
import cfml.dictionary.Return;
import cfml.dictionary.SyntaxDictionary;
import cfml.dictionary.Tag;
import com.cflint.CF;
import net.htmlparser.jericho.Element;

public class CFMLTagInfo {

private final SyntaxDictionary dictionary;

public CFMLTagInfo(final SyntaxDictionary dictionary) {
this.dictionary = dictionary;
}

/**
*
* @param element the element
* @param attributeName the attribute name
* @return true when the tag/attribute combination represents a variable
* assignment.
*/
public boolean isAssignmentAttribute(final Element element, final String attributeName) {
if (element != null) {
return isAssignmentAttribute(element.getName(), attributeName);
}
return false;
}

/**
*
* @param elementName the element
* @param attributeName the attribute name
* @return true when the tag/attribute combination represents a variable
* assignment.
*/
public boolean isAssignmentAttribute(final String elementName, final String attributeName) {
if (elementName != null && attributeName != null) {
// Hardcoded exceptions to the dictionary
if (elementName.equalsIgnoreCase(CF.CFPROCPARAM)) {
return "variable".equalsIgnoreCase(attributeName);
}
final Tag tag = dictionary.getTag(elementName.toLowerCase());
if (tag != null) {
for (final Object retObj : tag.getReturns()) {
final Return ret = (Return) retObj;
if (attributeName.equalsIgnoreCase(ret.getParameterName())) {
return true;
}
}
for (final Object paramObj : tag.getParameters()) {
final Parameter param = (Parameter) paramObj;
if (attributeName.equalsIgnoreCase(param.getName())) {
return "variablename".equalsIgnoreCase(param.getReturnVarType());
}
}
}
}
return false;
}

/**
*
* @param element the element
* @param attributeName the attribute name
* @return true when the tag/attribute combination represents a variable
* reference.
*/
public boolean isExpressionAttribute(final Element element, final String attributeName) {
if (element != null) {
return isExpressionAttribute(element.getName(), attributeName);
}
return false;
}

/**
*
* @param elementName the element
* @param attributeName the attribute name
* @return true when the tag/attribute combination represents a variable
* reference.
*/
public boolean isExpressionAttribute(final String elementName, final String attributeName) {
if (isAssignmentAttribute(elementName, attributeName)) {
return true;
}
if ((elementName != null) && (attributeName != null)) {
final Tag tag = dictionary.getTag(elementName.toLowerCase());
if (tag != null) {
for (final Object paramObj : tag.getParameters()) {
final Parameter param = (Parameter) paramObj;
if (attributeName.equalsIgnoreCase(param.getName())) {
return "query".equalsIgnoreCase(param.getType())
|| "variableName".equalsIgnoreCase(param.getType())
|| "array".equalsIgnoreCase(param.getType())
|| "struct".equalsIgnoreCase(param.getType())
|| "any".equalsIgnoreCase(param.getType());
}
}
}
}
return false;
}
}
package com.cflint.tools;

import cfml.dictionary.Parameter;
import cfml.dictionary.Return;
import cfml.dictionary.SyntaxDictionary;
import cfml.dictionary.Tag;
import com.cflint.CF;
import net.htmlparser.jericho.Element;

public class CFMLTagInfo {

private final SyntaxDictionary dictionary;

public CFMLTagInfo(final SyntaxDictionary dictionary) {
this.dictionary = dictionary;
}

/**
*
* @param element the element
* @param attributeName the attribute name
* @return true when the tag/attribute combination represents a variable
* assignment.
*/
public boolean isAssignmentAttribute(final Element element, final String attributeName) {
if (element != null) {
return isAssignmentAttribute(element.getName(), attributeName);
}
return false;
}

/**
*
* @param elementName the element
* @param attributeName the attribute name
* @return true when the tag/attribute combination represents a variable
* assignment.
*/
public boolean isAssignmentAttribute(final String elementName, final String attributeName) {
if (elementName != null && attributeName != null) {
// Hardcoded exceptions to the dictionary
if (elementName.equalsIgnoreCase(CF.CFPROCPARAM)) {
return "variable".equalsIgnoreCase(attributeName);
}
if (elementName.equalsIgnoreCase(CF.CFCOOKIE) && "name".equalsIgnoreCase(attributeName)) {
return false;
}
final Tag tag = dictionary.getTag(elementName.toLowerCase());
if (tag != null) {
for (final Object retObj : tag.getReturns()) {
final Return ret = (Return) retObj;
if (attributeName.equalsIgnoreCase(ret.getParameterName())) {
return true;
}
}
for (final Object paramObj : tag.getParameters()) {
final Parameter param = (Parameter) paramObj;
if (attributeName.equalsIgnoreCase(param.getName())) {
return "variablename".equalsIgnoreCase(param.getReturnVarType());
}
}
}
}
return false;
}

/**
*
* @param element the element
* @param attributeName the attribute name
* @return true when the tag/attribute combination represents a variable
* reference.
*/
public boolean isExpressionAttribute(final Element element, final String attributeName) {
if (element != null) {
return isExpressionAttribute(element.getName(), attributeName);
}
return false;
}

/**
*
* @param elementName the element
* @param attributeName the attribute name
* @return true when the tag/attribute combination represents a variable
* reference.
*/
public boolean isExpressionAttribute(final String elementName, final String attributeName) {
if (isAssignmentAttribute(elementName, attributeName)) {
return true;
}
if ((elementName != null) && (attributeName != null)) {
final Tag tag = dictionary.getTag(elementName.toLowerCase());
if (tag != null) {
for (final Object paramObj : tag.getParameters()) {
final Parameter param = (Parameter) paramObj;
if (attributeName.equalsIgnoreCase(param.getName())) {
return "query".equalsIgnoreCase(param.getType())
|| "variableName".equalsIgnoreCase(param.getType())
|| "array".equalsIgnoreCase(param.getType())
|| "struct".equalsIgnoreCase(param.getType())
|| "any".equalsIgnoreCase(param.getType());
}
}
}
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<cfcomponent>
<cffunction name="foo">
<cfcookie name="_dist" value="" expires="now" httponly="true">
</cffunction>
</cfcomponent>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version" : "",
"timestamp" : 0,
"issues" : [ ],
"counts" : {
"totalFiles" : 0,
"totalLines" : 0,
"countByCode" : [ ],
"countBySeverity" : [ ]
}
}

0 comments on commit 10a892c

Please sign in to comment.