-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[libc++][regex] Fix #51028 throw exception in the case of wrong range #148231
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
base: main
Are you sure you want to change the base?
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-libcxx Author: Lazarev Alexei (insanustu) ChangesStarting and ending parameters are considered to decide that a range is a correct one Full diff: https://github.com/llvm/llvm-project/pull/148231.diff 2 Files Affected:
diff --git a/libcxx/include/regex b/libcxx/include/regex
index bbc21e244dd17..958168a88535d 100644
--- a/libcxx/include/regex
+++ b/libcxx/include/regex
@@ -2120,7 +2120,7 @@ public:
__ranges_.push_back(
std::make_pair(__traits_.transform(__b.begin(), __b.end()), __traits_.transform(__e.begin(), __e.end())));
} else {
- if (__b.size() != 1 || __e.size() != 1)
+ if (__b.size() != 1 || __e.size() != 1 || __b[0] > __e[0])
std::__throw_regex_error<regex_constants::error_range>();
if (__icase_) {
__b[0] = __traits_.translate_nocase(__b[0]);
diff --git a/libcxx/test/std/re/re.regex/re.regex.construct/bad_range.pass.cpp b/libcxx/test/std/re/re.regex/re.regex.construct/bad_range.pass.cpp
index 023bc0ee79f44..f7ccf2d334022 100644
--- a/libcxx/test/std/re/re.regex/re.regex.construct/bad_range.pass.cpp
+++ b/libcxx/test/std/re/re.regex/re.regex.construct/bad_range.pass.cpp
@@ -33,6 +33,7 @@ int main(int, char**)
{
assert(error_range_thrown("([\\w-a])"));
assert(error_range_thrown("([a-\\w])"));
+ assert(error_range_thrown("([w-a])"));
return 0;
}
|
Thanks! I edited the PR description to associate this PR with the issue to fix. |
✅ With the latest revision this PR passed the C/C++ code formatter. |
390e012
to
988130c
Compare
988130c
to
70ff63d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the fix!
libcxx/include/regex
Outdated
@@ -2120,7 +2120,7 @@ public: | |||
__ranges_.push_back( | |||
std::make_pair(__traits_.transform(__b.begin(), __b.end()), __traits_.transform(__e.begin(), __e.end()))); | |||
} else { | |||
if (__b.size() != 1 || __e.size() != 1) | |||
if (__b.size() != 1 || __e.size() != 1 || __b[0] > __e[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be using char_traits::lt
to perform this comparison though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
70ff63d
to
09f38bc
Compare
This can be merged once CI is green (whoever sees it first). |
Starting and ending parameters are considered to decide that a range is a correct one
Fix #51028