ColdFusion language (CFML) seems to interpret the NULL character (which is 0x00000000, or chr(0)) as an empty string instead of a valid character. It would be easy to see why most programmers don't care, however this is a significant issue.
Take for example, if you are encrypting strings. Lets say you have a 10-character long string, and you are encrypting it character-by-character. So loop through all 10 chars, encrypt each one and append it to a new string, right? Ok, what if one of the encrypted values is null, or chr(0)? This actually happened to me, so don't think it never happens.
So what happened to me? I looped through 10 times, encrypted each character, built the new string, and then for some unknown reason, my new string was only 9 characters long instead of 10. Why?
Well, one of the characters encrypted to be chr(0), and I appended it to my new string, however it since ColdFusion treats chr(0) as "" (empty string), appending it to my string resulting in no change -- nothing appended. Thus my encrypted string was 9 chars instead of 10 and completely useless.
Some potential solutions:
The first solution I came up with was if I am passing this info to another page or application (which was the case), then I can simply URL encode the string and pass it along. When my encryption algorithm runs, now I am checking if the value is 0, and instead of appending chr(0), I append "" which is the URL Encoded version of the same thing. This works so long as the recipient (a .Net server in my case) URL Decodes the string first.
As I did further testing, I figured out that if I URL decoded that string within ColdFusion, the null char actually shows up!
So I put 1 and 1 together, and ended up with an interesting conclusion. If decoding a URL encoded null character works, then I can just append that to my string and see if it work... and it does!
This does NOT Work:
<cfset mystring = "abc123" & chr(0)> <!--- length will be 6 --->
This DOES work:
<cfset mystring = "abc123" & URLDecode("")> <!--- length will be 7 --->
I hope this is of some value to somebody.