stevieb has asked for the wisdom of the Perl Monks concerning the following question:
Good day my fellow esteemed Monks!
I come to you today with what I think is an easy one... I'm doing a validation check on input data, but I'm not getting expected results. Down deep in my software I've got the following sub, which compares a value against a list of enum type values. The important part for this discussion is the regex check:
sub enum { my ($attr, $value, $constraints) = @_; my $enum_values = $constraints->{enum}; if (scalar @$enum_values) { if (! (grep /^$value$/, @$enum_values)) { my $enum_values_string = join ', ', @$enum_values; return "Attribute $attr is enum type but value '$value' is +n't one of '$enum_values_string'"; } } return 0; }
Here's the test failure, which shows the actual value I'm trying to send in, along with the actual allowed values. You can see by eye that there's a match (the "isn't one of" is a joined string of the allowed values, separated by comma):
Attribute PoweredBy is enum type but value 'None (Private Label)' isn't one of 'None (Private Label), Text, Banner, Extra' at tests/Email/035_email_model_broadcast.t line 199.Is this a failure due to the parens not being escaped? What's the best way to handle this? I'd rather not have to escape the input data, and I can't manually escape the allowed values in the sub above as the data is pulled from a database.
Thanks,
-stevieb
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Do I need to do escaping in my regex check?
by choroba (Cardinal) on Mar 14, 2022 at 14:34 UTC | |
|
Re: Do I need to do escaping in my regex check?
by hv (Prior) on Mar 14, 2022 at 14:39 UTC | |
|
Re: Do I need to do escaping in my regex check?
by LanX (Saint) on Mar 14, 2022 at 14:43 UTC |