Skip to content

Commit

Permalink
Fix problematic regular expressions reported by SonarCloud
Browse files Browse the repository at this point in the history
  • Loading branch information
nadvornik authored and cbosdo committed Oct 9, 2023
1 parent 33d5f90 commit 9c4ffcc
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion java/code/src/com/redhat/rhn/common/security/acl/Acl.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public class Acl {
private static final String ACL_SPLIT_REGEX = "\\s*;\\s*";

/** RegEx to split expressions into multiple statements */
private static final String EXPR_SPLIT_REGEX = "\\s+or\\s+";
private static final String EXPR_SPLIT_REGEX = "\\s++or\\s++";

/** RegEx to parse statement to grab negation, function call, params */
private static final String STMT_PARSE_REGEX = "^(not +)?(.*)\\((.*)\\)$";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1020,11 +1020,7 @@ public String getBootloaderType() {
return "grub";
}

String regEx = ".*--useLilo.*";
Pattern pattern = Pattern.compile(regEx);
Matcher matcher = pattern.matcher(bootloaderCommand.getArguments());

if (matcher.matches()) {
if (bootloaderCommand.getArguments().contains("--useLilo")) {
return "lilo";
}
return "grub";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ protected StreamInfo getStreamInfo(ActionMapping mapping, ActionForm form,
// Read the CSV separator from user preferences
User user = new RequestContext(request).getCurrentUser();
CSVWriter csvWriter = new CSVWriter(new StringWriter(), user.getCsvSeparator());
String[] columns = exportColumns.split("\\s*,\\s*");
String[] columns = exportColumns.split("\\s*+,\\s*+");
csvWriter.setColumns(Arrays.asList(columns));

String header = getHeaderText(request, session);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(" *+, *+"));
for (String typeName : typeNames) {
types.put(
LocalizationService.getInstance().getPlainText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(" *+, *+"));
}
return new ArrayList<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static ValidatorResult validateContent(String content,
// One or more chars NOT parentheses$1,
// followed by zero or one "( any-chars$3 ) $2",
// followed by zero or one "= any-chars$5 $4"
String macroStr = "([^()]+)(\\((.*?)\\))?\\s*(=(.*))?";
String macroStr = "([^()]++)(\\((.*?)\\))?\\s*+(=(.*+))?";

Pattern findMacro = Pattern.compile(findMacroStr,
Pattern.MULTILINE + Pattern.DOTALL);
Expand Down
4 changes: 2 additions & 2 deletions java/code/src/com/suse/manager/reactor/utils/RhelUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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);

/**
* Information about RHEL based OSes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1712,10 +1712,10 @@ private Map<LocalCall<?>, List<MinionSummary>> scapXccdfEvalAction(
if (tailoringIdMatcher.find()) {
pillar.put("tailoring_id", tailoringIdMatcher.group(1));
}
if (scapActionDetails.getParametersContents().matches(".*--fetch-remote-resources.*")) {
if (scapActionDetails.getParametersContents().contains("--fetch-remote-resources")) {
pillar.put("fetch_remote_resources", true);
}
if (scapActionDetails.getParametersContents().matches(".*--remediate.*")) {
if (scapActionDetails.getParametersContents().contains("--remediate")) {
pillar.put("remediate", true);
}

Expand Down

0 comments on commit 9c4ffcc

Please sign in to comment.