Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added canonicalize method (and tests) to securityutil file #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Copy the `securityutil.cfc` file into your project and then:
```cfm
<cfset securityUtil = CreateObject("component", "securityutil")>
<cfoutput>
Hello #securityUtil.canonicalize(url.name)# <br /> <!--- ESAPI canonicalize --->
Hello #securityUtil.encodeHTML(url.name)# <br /> <!--- ESAPI encodeForHTML --->
Hello #securityUtil.scrub(url.name)# <!--- remove all but a-z0-9 --->
</cfoutput>
Expand Down
12 changes: 12 additions & 0 deletions securityutil.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@
</cfif>
</cffunction>

<cffunction name="canonicalize" output="false" hint="Runs the ESAPI canonicalize method using either CFs builtin or falls back on java.">
<cfargument name="input" hint="The string to encode.">
<cfargument name="restrictMultiple" type="boolean" required="true" default="false" hint="If set to true, multiple encoding is restricted.">
<cfargument name="restrictMixed" type="boolean" required="true" default="false" hint="If set to true, mixed encoding is restricted.">
<cfif variables.esapiBuiltin>
<cfreturn canonicalize(arguments.input, arguments.restrictMultiple, arguments.restrictMixed)>
<cfelse>
<cfset assertInit()>
<cfreturn variables.esapi.encoder().canonicalize(arguments.input)>
</cfif>
</cffunction>

<cffunction name="encodeHTML" output="false" hint="Runs the ESAPI encodeForHTML method using either CFs builtin or falls back on java.">
<cfargument name="input" hint="Currently supports string input but eventually it could operate on an entire data structure at once, eg struct query">
<cfif variables.esapiBuiltin>
Expand Down
12 changes: 12 additions & 0 deletions tests/CanonicalizeTest.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<cfcomponent extends="base">

<cffunction name="testSimple">
<cfset assertEquals("test", getSecurityUtil().canonicalize("test"))>
</cffunction>

<cffunction name="testTag">
<cfset assertEquals("<pete />", getSecurityUtil().canonicalize("&lt;pete &##x2f;&gt;"))>
</cffunction>


</cfcomponent>