Skip to content

Commit

Permalink
Fix StringIndexOutOfBoundsException (#1618)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet authored Aug 12, 2024
1 parent 97bc109 commit 9c1871f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
38 changes: 22 additions & 16 deletions maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -1421,16 +1421,19 @@ static void performProjectActivation(final CommandLine commandLine, final Projec
for (String token : optionValue.split(",")) {
String selector = token.trim();
boolean active = true;
if (selector.charAt(0) == '-' || selector.charAt(0) == '!') {
active = false;
selector = selector.substring(1);
} else if (token.charAt(0) == '+') {
if (!selector.isEmpty()) {
if (selector.charAt(0) == '-' || selector.charAt(0) == '!') {
active = false;
selector = selector.substring(1);
} else if (token.charAt(0) == '+') {
selector = selector.substring(1);
}
}
boolean optional = false;
if (!selector.isEmpty() && selector.charAt(0) == '?') {
optional = true;
selector = selector.substring(1);
}

boolean optional = selector.charAt(0) == '?';
selector = selector.substring(optional ? 1 : 0);

projectActivation.addProjectActivation(selector, active, optional);
}
}
Expand All @@ -1450,16 +1453,19 @@ static void performProfileActivation(final CommandLine commandLine, final Profil
for (String token : optionValue.split(",")) {
String profileId = token.trim();
boolean active = true;
if (profileId.charAt(0) == '-' || profileId.charAt(0) == '!') {
active = false;
profileId = profileId.substring(1);
} else if (token.charAt(0) == '+') {
if (!profileId.isEmpty()) {
if (profileId.charAt(0) == '-' || profileId.charAt(0) == '!') {
active = false;
profileId = profileId.substring(1);
} else if (token.charAt(0) == '+') {
profileId = profileId.substring(1);
}
}
boolean optional = false;
if (!profileId.isEmpty() && profileId.charAt(0) == '?') {
optional = true;
profileId = profileId.substring(1);
}

boolean optional = profileId.charAt(0) == '?';
profileId = profileId.substring(optional ? 1 : 0);

profileActivation.addProfileActivation(profileId, active, optional);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,20 @@ public void testPropertiesInterpolation() throws Exception {
assertThat(request.getCommandLine().getArgs(), equalTo(new String[] {"prefix:3.0.0:bar", "validate"}));
}

@Test
public void testEmptyProfile() throws Exception {
CliRequest request = new CliRequest(new String[] {"-P", ""}, null);
cli.cli(request);
cli.populateRequest(request);
}

@Test
public void testEmptyProject() throws Exception {
CliRequest request = new CliRequest(new String[] {"-pl", ""}, null);
cli.cli(request);
cli.populateRequest(request);
}

@ParameterizedTest
@MethodSource("activateBatchModeArguments")
public void activateBatchMode(boolean ciEnv, String[] cliArgs, boolean isBatchMode) throws Exception {
Expand Down

0 comments on commit 9c1871f

Please sign in to comment.