Boost logo

Boost Users :

From: John Maddock (john_at_[hidden])
Date: 2007-02-25 05:27:52


Michael Radzewitz wrote:
> Hello everyone,
>
> i have a problem with libboost_regex-gcc-mt-1_33_1.a on a debian Linux
> and a simple function to test some Names:
>
> bool is_valid_name(const char *s)
> {
> if(!s)
> return false;
>
> const char* re = "^[a-zA-Z][.*0-9a-zA-Z._-]{4,60}$";
>
> static const boost::regex e(re);
> return regex_match(s,e);
> }
>
>
> Everything works well when i put this Funtion in a simple Programm
> and run it.
> When I put the same Function in my cgi which is wrapped through
> fastCgi and handled by an apache webserver i get the following
> Error message:
>
> Invalid content of repeat range
>
> so in a simple programm the range check {4,60} in boost regex works
> but in a more complex program it didd'nt.
>
> I have testet the same function on Linux using:
> libboost_regex-gcc-mt-1_33_1.a and free BSD using:
> libboost_regex.so.3 and get with both libs the same
> error message.
>
> It would be nice if someone can help me find a solution or tell me
> what
> went wrong here.

I'm not able to reproduce that, parsing of {x,y} replies on std::locale
num_get facets, so I guess things to check are:

1) What's the locale of the program? Is it something different under your
web server so that 4 and 60 aren't recognised as numbers anymore? Seems
unlikely though.
2) I notice that the regex instance is static, are there any
order-of-initialization issues - for example the regex being initialised
before the std lib? I can't imagine this one either really :-(
3) Is there more than one copy of the regex .so on the system?

If you suspect locale issues, you could try using basic_regex<char,
c_regex_traits<char> > (this uses the C locale rather than std::locale) and
see if this helps, or else imbue the regex with std::locale("C") *before*
you assign the regex to it:

const boost::regex& get_regex()
{
  static bool init = false;
  static boost::regex e;
  if(!init)
  {
    e.imbue(std::locale("C"));
    e.assign("^[a-zA-Z][.*0-9a-zA-Z._-]{4,60}$");
  }
  return e;
}

But really these kinds of workarounds shouldn't be needed.

Not sure if this helps,

John.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net