Last active
July 1, 2022 18:29
-
-
Save JamoCA/876e577d3f69b516d0224b03f87f9c1d to your computer and use it in GitHub Desktop.
Strange Comparison Issue (Strings that look like numbers fail comparison when using ColdFusion 2021)
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
<!--- 20200630 Adobe ColdFusion 2021 returns different results than CF2018, CF2016 and Lucee 4.5 & 5. | |
Discussion https://community.adobe.com/t5/coldfusion-discussions/strange-comparison-issue/m-p/13041667 | |
Reported Bug: https://tracker.adobe.com/#/view/CF-4214261 | |
Tweet: https://twitter.com/gamesover/status/1542938151441666048 | |
---> | |
<cfset A = javacast("string", "147.xxx.yyy.zzz")> | |
<cfoutput><pre> | |
#A#--- | |
Left 4: #Left(A,4)#--- | |
Left 4 eq: #yesNoFormat(Left(A,4) eq "147.")# | |
Left 4 is: #yesNoFormat(Left(A,4) is "147.")# | |
Left 4 equal: #yesNoFormat(Left(A,4) equal "147.")# | |
Left 4 CFIf eq: #yesNoFormat(Left(A,4) eq "147.")# | |
Mid dot: #yesNoFormat(Mid(A,4,1) eq ".")# | |
Left 3 Compare: #yesNoFormat(Left(A,3) eq "147")# | |
First Item in List: #yesNoFormat(GetToken(A,1,".") eq "147")# | |
--- | |
Compare: #yesNoFormat(not compare(Left(A,4), "147."))# | |
Left 4 is/Cast: #yesNoFormat(Left(A,4) is javacast("string","147."))# | |
</pre></cfoutput> | |
<cfscript> | |
initVal = "147.xxx"; | |
tests = [ | |
"noCast": left(initVal, 4) is "147." | |
,"bothCast": left(javacast("string", initVal), 4) is javacast("string", "147.") | |
,"leftCast": left(javacast("string", initVal), 4) is "147." | |
,"rightCast": left(initVal, 4) is javacast("string", "147.") | |
]; | |
writeDump(var=tests, label="Using Var: These are all true, except for CF2021"); | |
tests2 = [ | |
"noCast": left("147.xxx", 4) is "147." | |
,"bothCast": left(javacast("string", "147.xxx"), 4) is javacast("string", "147.") | |
,"leftCast": left(javacast("string", "147.xxx"), 4) is "147." | |
,"rightCast": left("147.xxx", 4) is javacast("string", "147.") | |
]; | |
writeDump(var=tests2, label="Using Inline: These are all true, except for CF2021"); | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment