It looks like a minus but it is not: \u2013

24 09 2008

Today a colleague came to me with a rather curious error. He had made a UDF, containing the following line of code:
ZS = (arguments.rawScore – arguments.mean) / arguments.SD;
All referenced arguments existed (we checked that multiple times :) ) and – as you may see, the expression structure seems to be valid (the UDF was written in cfscript).

Still, calling the UDF consistently resulted in the following error:

Invalid CFML construct found on line XX at column XX.

ColdFusion was looking at the following text:

\u2013

After a few minutes of astonishment another colleague suggested to take a good look at the character at the position reported in the error message. This turned out to be the  – in the above line. Nothing seemed wrong with it, but replacing it with a – turned out to fix the problem.

Huh? I could not see the difference either, but the original – had been copied and pasted from a MS Word document, and in fact was not a minus but a unicode ‘EN DASH’ (U+2013). This character is not a minus so ColdFusion was correct in reporting the error. Apparently MS Word had figured out that my colleague actually meant to write an ‘EN DASH’ when he pressed the minus key on his keyboard. Just another reason not to use MS Word to wite down code. Not even short snippets of code, as part of taking notes in a discussion!