Title:
String member functions break existing code that relies on java.lang.String member functions
| View in TrackerStatus/Resolution/Reason: Closed/Fixed/
Reporter/Name(from Bugbase): Sean Corfield / Sean Corfield (Sean Corfield)
Created: 05/01/2014
Components: Core Runtime
Versions: 11.0
Failure Type:
Found In Build/Fixed In Build: PublicBeta /
Priority/Frequency: Major / Some users will encounter
Locale/System: ALL / Mac 10.8 64-bit
Vote Count: 17
Problem Description: Code that relies on myStr.replace(a,b) to support a possibly being an empty string now breaks.
Steps to Reproduce:
<cfset s = "SOMETHING">
<cfset a = "">
<cfoutput>#s.replace(a,"")#</cfoutput>
Actual Result: Exception: Argument 2 of function Replace cannot be an empty value.
Expected Result: Should output SOMETHING like it did in all prior versions of ACF (and like it does in Railo, even current versions that support string member functions).
Any Workarounds: Add ugly conditional code to handle empty strings.
Several issues here:
1. The reason folks used s.replace() in the first place was because replace(s,"","") fails because it arbitrarily rejects the second argument being an empty string, whereas the underlying java.lang.String::replace() method is perfectly happy with an empty string.
2. The exception is very misleading - and I bet this applies to all member functions - because the argument numbers refer to the original Built-In Functions, not the member functions. In this case "Argument 2" is actually the _first_ argument to s.replace() and "Argument 3" would be the _second_ argument.
3. This shows you didn't even try to test this will FW/1 - one of the most popular CFML frameworks out there - because out of the box, several examples fail because they contain expressions like this (to account for the optional context root in Java web applications):
variables.framework = {
base = getDirectoryFromPath( CGI.SCRIPT_NAME ).replace( getContextRoot(), '' ) & 'introduction'
};
----------------------------- Additional Watson Details -----------------------------
Watson Bug ID: 3753710
External Customer Info:
External Company:
External Customer Name: SeanACorfield
External Customer Email:
External Test Config: My Hardware and Environment details:
Attachments:
Comments: