ColdFusion String Length != JavaScript String Length
Here's a bizarre issue I just ran into today that I had never seen before. The length of ColdFusion strings is not calculated the same way that JavaScript calculates string length.
We have a text entry box for people to enter a summary about about a given item. We were using some JavaScript code built into qForms to display a "X Characters Remaining" field to let the user know how much text they can enter.
Our tester was generating errors by pasting some text into this field and submitting it. If I dumped out the length of the incoming string, CF saw it as more characters than the maximum. Even though the JavaScript check was showing only the required limit of characters.
At first I thought maybe the qForms utility had a bug in it. But it turns out to be more fundamental than that. Apparently, Firefox follows the UNIX convention of treating a carriage return as a single character, even though IE and ColdFusion treat it as two (carriage return/line feed).
The way I see it we have three choices: either use the left() function to truncate the string; or use stripCR() to remove the carriage returns; or write (or download) a JavaScript function that automatically takes this into account while checking the text length. I think we've found a JS function that handles it, but I was a bit amazed that in all my years I had never seen or heard of this before. Has anyone else run into this? How did you handle it?





