on of the boost::regex_search result contains an extra character
- Dominant language
- C++
- Stars
- 119
- Forks
- 113
- PR merge metrics
- No merged PRs in 30d
Description
The issue was found in some custom URL parsing code, I am not sure this is a known issue.
I've isolated the issue to this tiny bit of code:
```
static boost::regex pattern(R"((&?([^&=]+)(=?([^&]*))))",
boost::regex_constants::extended | boost::regex_constants::optimize);
boost::smatch matches;
std::string testString = "SERVICE=WMTS&TileCol=1";
if (boost::regex_search(testString.cbegin(), testString.cend(), matches, pattern)) {
for (unsigned int i = 0; i < matches.size(); ++i) {
std::cout << i << ": " << std::string(matches[i].first, matches[i].second) << std::endl;
}
}
```
this will print
`0: SERVICE=WMTS
1: SERVICE=WMTS
2: SERVICE
3: =WMTS
4: =WMTS`
but I think the last item (number 4) should not have the '=' character present, you can check the regular expression on https://regex-vis.com/ that the = is out of group 4
if you switch to std regex
```
static std::regex pattern(R"((&?([^&=]+)(=?([^&]*))))",
std::regex_constants::extended | std::regex_constants::optimize);
std::smatch matches;
std::string testString = "SERVICE=WMTS&TileCol=1";
if (std::regex_search(testString.cbegin(), testString.cend(), matches, pattern)) {
for (size_t i = 0; i < matches.size(); ++i) {
std::cout << i << ": " << std::string(matches[i].first, matches[i].second) << std::endl;
}
}
```
it will print
`0: SERVICE=WMTS
1: SERVICE=WMTS
2: SERVICE
3: =WMTS
4: WMTS`
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the minimal boost::regex_search example in the issue and compare its capture ranges with the equivalent std::regex output. Trace the Boost.Regex matching behavior for the extended expression, then confirm completion when capture group 4 excludes the '=' character and the behavior has regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100