-
Notifications
You must be signed in to change notification settings - Fork 191
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
Fix problematic regular expressions reported by SonarCloud #6995
Conversation
Suggested tests to cover this Pull Request
|
12a53d6
to
11a1861
Compare
567be3c
to
7798518
Compare
@@ -240,7 +240,7 @@ public static SortedMap<String, String> setUpPowerTypes(HttpServletRequest reque | |||
SortedMap<String, String> types = new TreeMap<>(); | |||
String typeString = ConfigDefaults.get().getCobblerPowerTypes(); | |||
if (typeString != null) { | |||
List<String> typeNames = Arrays.asList(typeString.split(" *, *")); | |||
List<String> typeNames = Arrays.asList(typeString.split(" *+, *+")); |
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.
Wouldn't it be even better with "[^,]*+, *+"
?
@@ -71,7 +71,7 @@ public class PowerManagementHandler extends BaseHandler { | |||
public List<String> listTypes(User loggedInUser) { | |||
String typeString = ConfigDefaults.get().getCobblerPowerTypes(); | |||
if (typeString != null) { | |||
return Arrays.asList(typeString.split(" *, *")); | |||
return Arrays.asList(typeString.split(" *+, *+")); |
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.
Same here
@@ -37,11 +37,11 @@ public class RhelUtils { | |||
private RhelUtils() { } | |||
|
|||
private static final Pattern RHEL_RELEASE_MATCHER = | |||
Pattern.compile("(.+)\\srelease\\s([\\d.]+)\\s*\\((.+)\\).*", Pattern.DOTALL); | |||
Pattern.compile("(.+)\\srelease\\s([\\d.]+)\\s*+\\(([^)]++)\\).*+", Pattern.DOTALL); |
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.
Don't you need a +
to prevent backtracking in the first group too?
private static final Pattern ORACLE_RELEASE_MATCHER = | ||
Pattern.compile("(.+)\\srelease\\s([\\d.]+).*", Pattern.DOTALL); | ||
private static final Pattern ALIBABA_RELEASE_MATCHER = | ||
Pattern.compile("(.+)\\srelease\\s([\\d.]+)\\s*LTS\\s*\\((.+)\\).*", Pattern.DOTALL); | ||
Pattern.compile("(.+)\\srelease\\s([\\d.]+)\\s*+LTS\\s*+\\(([^)]++)\\).*+", Pattern.DOTALL); |
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.
Same here
This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 10 days. |
This PR was closed because it has been stalled for 10 days with no activity. |
Reopening: some questions haven't been answered |
What does this PR change?
This PR fixes some of the problematic regular expressions by using
String contains()
method or by using possessive quantifiers.GUI diff
No difference.
Documentation
Test coverage
Links
Partially fixes https://github.com/SUSE/spacewalk/issues/21403
Changelogs
Make sure the changelogs entries you are adding are compliant with https://github.com/uyuni-project/uyuni/wiki/Contributing#changelogs and https://github.com/uyuni-project/uyuni/wiki/Contributing#uyuni-projectuyuni-repository
If you don't need a changelog check, please mark this checkbox:
If you uncheck the checkbox after the PR is created, you will need to re-run
changelog_test
(see below)Re-run a test
If you need to re-run a test, please mark the related checkbox, it will be unchecked automatically once it has re-run: