Created
December 22, 2022 19:18
-
-
Save JamoCA/8ccc609618d575d4c87986681d789d13 to your computer and use it in GitHub Desktop.
Testing ColdFusion/CFML Replace Regex Limits
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
<!--- 20221222 Testing CFML Replace Regex Limits | |
Blog: https://dev.to/gamesover/use-java-replaceall-instead-of-coldfusion-rereplacenocase-ee4 | |
Bug: https://tracker.adobe.com/#/view/CF-4165797 | |
Bug: https://tracker.adobe.com/#/view/CF-3928688 | |
YMMV based on CF version, JVM and regex used, but using native replaceAll() seems to be more reliable & faster | |
when performing lots of replacements. | |
When using ACF2016, we encountered intermittent, unpreventable/uncatchable hard ColdFusion errors. (Using CFTRY/CATCH | |
wouldn't do anything and we had to refer to log files to identify the errors.) | |
CF2016/18 seems to have a maximum 1587 character limit with this regex. CF2021 is higher. | |
---> | |
<cfset repeatCount = 50> | |
<cfset textString = "start <!--[CODE]--> #repeatstring('a lot of generic text... ', repeatCount)# <!--[/CODE]--> end"> | |
<cfset test = [ | |
"largeString": textString, | |
"largeString_len": len(textString), | |
"cfml_reReplace": "fail", | |
"cfml_reReplaceNoCase": "fail", | |
"java_replaceAll": "fail" | |
]> | |
<!--- ACF starts to fail at around 1587 characters. CFTry/Catch don't do anything. Comment out CFML & increase repeatCount to test. ---> | |
<cftry> | |
<cfset test.cfml_reReplace = rereplace(test.largeString,"(<!--\[CODE\]-->)(.|\n)*?(<!--\[/CODE\]-->)", "", "all")> | |
<cfcatch></cfcatch> | |
</cftry> | |
<cftry> | |
<cfset test.cfml_reReplaceNoCase = rereplacenocase(test.largeString,"(<!--\[CODE\]-->)(.|\n)*?(<!--\[/CODE\]-->)", "", "all")> | |
<cfcatch></cfcatch> | |
</cftry> | |
<!--- java replaceAall works w/higher limits & appears to be faster ---> | |
<cftry> | |
<cfset test.java_replaceAll = javacast("string", test.largeString).replaceAll("(?ims)(<!--\[CODE\]-->)(.|\n)*?(<!--\[/CODE\]-->)", "")> | |
<cfcatch></cfcatch> | |
</cftry> | |
<cfdump var="#test#" label="Regex Replace Test Results"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment