ColdFusion and the expression does not contain is broken

While trying to find a problem with some code today, I cam across an interesting problem that had me stumped. And for the life of me, I could not work out what was going on with it either.

But it appears that when doing an expression on a variable with 'does not contain' actually doesn't work, in any way shape or form.

Sometime ago I had seen the following bit of code in something I was maintaining, and decided to refactor it.

<cfcatch type="Database">
   <cfif cfcatch.detail contains "duplicate key">
   <cfelse>
      <cfdump var="#cfcatch#" /> <cfabort />
   </cfif>
</cfcatch>

What I had done was refactored the code to this.

<cfcatch type="Database">
   <cfif cfcatch.detail does not contain "duplicate key">
      <cfdump var="#cfcatch#" /> <cfabort />
   </cfif>
</cfcatch>

And what surprised me was that it didn't work the way I had intended it to work, it appears that over some time this got broken in ColdFusion.

 

I spent a good deal of time trying to figure this out, and I am not 100% sure but it appears that the space in the cfcatch details is not a normal ASCII space. Whatever is the problem, it goes to show how somewhere some how what you think is right, isn't always what it appears to be.


ColdFusion and the expression does not contain is broken - http://cfbloggers.org/?c=44545 Sep 20, 2010

  • David R's Gravatar @Andy,

    It should be 'DOES NOT CONTAIN', and it seems you've wrongly given that as 'DOES NOT CONTAINS', thats why you are not able to get it working.
    # Posted By David R | 9/19/10 11:51 PM
  • damen's Gravatar is that a typo?

    dont you want to use

    DOES NOT CONTAIN ?

    instead of DOES NOT CONTAINS its in the try context too so it wont throw.

    Its a gramatical syntax error? good luck...
    # Posted By damen | 9/19/10 11:58 PM
  • Andrew Scott's Gravatar Cheers for pointing this out to me, I have changed the body of the text to reflect this fix.

    Now as for it being inside a try catch block, would you care to read that line of code again and tell me the same thing?

    I ran this with a line debugger, and watched it fail each and everytime. I also saw that the cfcacth.details actually had the condition I was trying to ignore. And yet it still didn't match the condition, this is where the line debugger is handy because you not only see the execution of each line but you get to see what everything contains at each line at runtime.
    # Posted By Andrew Scott | 9/20/10 12:21 AM
  • Azadi Saryev's Gravatar did you check to see if <cfif not (cfcatch.detail contains "duplicate key")> works as expected?

    i would think that the content of cfcatch.detail does not change based on if you use 'contains' or 'does not contain' comparison  - so if contains operator works correctly, and does not contain doesn't, then it's something else at play here, not the spaces in the text...
    # Posted By Azadi Saryev | 12/22/10 1:17 AM
  • Andrew Scott's Gravatar I want to be point blank here, nobody has tried it have they?

    And considering I refactered the code, I think you might want to take another look at the problem I described first.
    # Posted By Andrew Scott | 12/23/10 1:36 AM