Last active
December 30, 2015 11:19
-
-
Save aliaspooryorik/7821904 to your computer and use it in GitHub Desktop.
Script to find missing or suspicious output attributes in components
This file contains hidden or 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
<cfset folder = expandpath("./")> | |
<cfset warn = []> | |
<cfset alert = []> | |
<cfdirectory action="list" directory="#folder#" filter="*.cfc" recurse="true" name="cfcs" type="file"> | |
<cfoutput> | |
<style> | |
* {font-family:Courier; font-size:11px;} | |
</style> | |
<p>#cfcs.recordcount# .cfc files found in folder '#folder#'.</p> | |
<cfloop query="cfcs"> | |
<cfset results = analyzeTags(cfcs.directory & '/' & cfcs.name)> | |
Results for: #replace(cfcs.directory, folder, "")#/#cfcs.name#<br> | |
<span style="color:green">Passed: #arraylen(results.passed)#<br> | |
<cfloop array="#results.passed#" index="info"> #htmleditformat(info)#<br></cfloop> | |
</span> | |
<span style="color:orange">Warn: #arraylen(results.warn)#<br> | |
<cfloop array="#results.warn#" index="info"> #htmleditformat(info)#<br></cfloop> | |
</span> | |
<span style="color:red">Alert: #arraylen(results.alert)#<br> | |
<cfloop array="#results.alert#" index="info"> #htmleditformat(info)#<br></cfloop> | |
</span> | |
<hr> | |
<cfflush> | |
</cfloop> | |
</cfoutput> | |
<cfscript> | |
function analyzeTags(required filepath){ | |
local.result = { | |
warn = [], | |
alert = [], | |
passed = [] | |
}; | |
local.filecontent = fileread(arguments.filepath); | |
local.result = analyze('cfcomponent', local.filecontent, local.result); | |
return analyze('cffunction', local.filecontent, local.result); | |
} | |
function analyze(tag, filecontent, result){ | |
local.pattern = "<#arguments.tag#[^>]+>"; | |
local.matches = rematchnocase(local.pattern, arguments.filecontent); | |
for (local.functiontag in local.matches){ | |
if (refindnocase("output\s*=", local.functiontag)){ | |
// output attribute found so what value does it have? | |
if (refindnocase("output\s*=\s*[""']?(no|false)[""']?", local.functiontag)){ | |
arrayappend(arguments.result.passed, local.functiontag); | |
} | |
else if (refindnocase("output\s*=\s*[""']?(yes|true)[""']?", local.functiontag)){ | |
arrayappend(arguments.result.warn, local.functiontag); | |
} | |
else{ | |
arrayappend(arguments.result.alert, local.functiontag); | |
} | |
} | |
else{ | |
// not found | |
arrayappend(arguments.result.alert, local.functiontag); | |
} | |
} | |
return arguments.result; | |
} | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment