-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<regex>: Regex erroneously returns a match #994
Comments
If I understand correctly, std::regex_match would never be invoked here because the constructor of std::regex has to throw if the regular expression is not valid. It should throw a std::regex_error with code std::regex_constants::error_brack. |
This is valid, #include<regex>
#include<iostream>
int main() {
std::regex regex("[a[a]*");
std::string str("[[[[[[aaaa");
std::cout << std::regex_match(str, regex);//1
} As to Lines 4020 to 4025 in 40640c6
The standard requires Lines 377 to 380 in 40640c6
And Lines 3018 to 3024 in 40640c6
I'm afraid #include<regex>
#include<iostream>
int main() {
std::regex regex("[[.(.]]*");
std::cout << std::regex_match("(((", regex);//0
std::cout << std::regex_match("(((v", regex);//0
std::cout << std::regex_match("v", regex);//1
std::cout << std::regex_match("w", regex);//1
std::cout << std::regex_match("vv", regex);//0
std::cout << "\n";
regex = "[[.(.]x]*";
std::cout << std::regex_match("xxx", regex);//1
std::cout << std::regex_match("xxxv", regex);//1
std::cout << std::regex_match("xxxw", regex);//1
std::cout << std::regex_match("xxxvv", regex);//0
std::cout << std::regex_match("vxxx", regex);//0
std::cout << std::regex_match("v", regex);//1
std::cout << std::regex_match("w", regex);//1
std::cout << std::regex_match("vv", regex);//0
}
|
Describe the bug
Regex returns a match where it is not expected to return a match.
Note that the pattern has mismatched
[
and]
.Need to clarify if it should actually throw, or the behavior is undefined.
Command-line test case
Expected behavior
DevCom-306176 reporter expects:
I expect an exception.
STL version
Additional context
Add any other context about the problem here.
This item is also tracked on Developer Community as DevCom-306176 and by Microsoft-internal VSO-660624 / AB#660624.
The text was updated successfully, but these errors were encountered: