-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
184aa39
commit 10a892c
Showing
4 changed files
with
129 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/test/resources/com/cflint/tests/VarScoper/cfcookie_518.cfc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
11 changes: 11 additions & 0 deletions
11
src/test/resources/com/cflint/tests/VarScoper/cfcookie_518.expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" : [ ] | ||
} | ||
} |