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


In reply to Do I need to do escaping in my regex check? by stevieb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.