"Invalid range end in character class" for dash after character range
- Dominant language
- C++
- Stars
- 119
- Forks
- 113
- PR merge metrics
- No merged PRs in 30d
Description
## Summary
For most other regex engines, `[X-Y-Z]` is a valid character set, consisting of character range X to Y, literal dash `-`, and character Z. For example, you can verify at https://regex101.com/ that this is valid for all regex flavors it supports.
Currently Boost rejects this under the default syntax. It's not clear from the [documentation](https://www.boost.org/doc/libs/1_83_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html) whether this is valid for Boost. This can be easily fixed by e.g. changing to `[X-YZ-]` but I'm still interested in knowing if rejecting this is intentional.
I encountered this when migrating from `std::regex`. This is explicitly valid for `std::regex`:
https://en.cppreference.com/w/cpp/regex/ecmascript:
> The character - is treated literally if it is
> * immediately follows a dash-separated range specification.
## Minimal reproducible example
### Code
```
#include
int main() {
const boost::regex re("[0-9-#]+");
return boost::regex_match("12#34-56", re);
}
```
### Expected behavior
Returns 1
### Actual behavior
```
terminate called after throwing an instance of 'boost::wrapexcept'
what(): Invalid range end in character class The error occurred while parsing the regular expression: '[0-9->>>HERE>>>#]+'.
Program terminated with signal: SIGSEGV
```
## Proposed fixes
* Determine whether we intend to accept or reject such syntax.
* If yes, change parsing code accordingly.
* In either case, clarify in the documentation
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the behavior with the minimal example using boost/regex.hpp, then read the linked Perl syntax documentation and compare its rules with the reported std::regex behavior. Determine whether the syntax should be accepted or rejected. Done means the parser behavior is resolved and the Boost regex documentation clearly states the decision.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- developer-experience
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100