I have this little component in ColdFusion 9:
component
displayname = "My Component"
accessors = "true"
{
property
name = "myProperty"
type = "string"
validate = "regex"
validateparams = "{ pattern = '(Eats)|(Shoots)|(Leaves)' }";
}
which works as expected:
<cfscript>
myComponentInstance = new myComponent();
myComponentInstance.setMyProperty('Eats');
// Property is correctly set
myComponentInstance.setMyProperty('Shoots');
// Property is correctly set
myComponentInstance.setMyProperty('Drinks');
// Error: The value does not match the regular expression pattern provided.
</cfscript>
But if I modify the validation regex to allow a value like with a comma (,) in it
validateparams = "{ pattern = '(Eats)|(Shoots)|(Leaves)|(Eats, Shoots & Leaves)' }"
then I get an error on the instance creation
<cfscript>
myComponentInstance = new myComponent();
/* Error while parsing the validateparam
'{ pattern = '(Eats)|(Shoots)|(Leaves)|(Eats, Shoots & Leaves)' }'
for property myProperty */
</cfscript>
It seems like ColdFusion can't process a regular expression with a comma, nor have I found a way of escaping it.
If I try to use a backslash (\), as a regex escaping character, it is then processed as a foreslash (/) by ColdFusion:
validateparams = "{ pattern = '(Eats)|(Shoots)|(Leaves)|(Eats\, Shoots & Leaves)' }"
<cfscript>
myComponentInstance = new myComponent();
/* Error while parsing the validateparam
'{ pattern = '(Eats)|(Shoots)|(Leaves)|(Eats/, Shoots & Leaves)' }'
for property myProperty */
</cfscript>
Other forms of escaping that I have tried, but to no avail, are:
validateparams = "{ pattern = '(Eats)|(Shoots)|(Leaves)|(Eats#chr(44)# Shoots & Leaves)' }"
validateparams = "{ pattern = '(Eats)|(Shoots)|(Leaves)|(Eats,, Shoots & Leaves)' }"
It's a bug in ColdFusion. Raise it as such: https://bugbase.adobe.com/. I can replicate it in CF 9.0.1. I'm working on a work-around... will get back to you if I come up with something.
NB: one can pare the repro validateparams
string down to this: {pattern = ","}
. I'm guessing Adobe are using the comma as a delim, and it never occurred to them it might be data (they're a bit like that with delimited strings).