Skip to main content

Posts

Showing posts from May, 2006

Using NULL characters in a ColdFusion string

The issue: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 r…