fix: do not split on space for option errors (#25876)
closes #25783 Signed-off-by: Steve Hawkins <shawkins@redhat.com>
This commit is contained in:
parent
8ff9e71eae
commit
7bde7c30cc
3 changed files with 26 additions and 7 deletions
|
@ -114,6 +114,18 @@ it must instead be individual arguments
|
|||
bin/kc.sh start --help
|
||||
```
|
||||
|
||||
Similarly instead of
|
||||
|
||||
```
|
||||
bin/kc.sh build "--db postgres"
|
||||
```
|
||||
|
||||
it must instead be individual arguments
|
||||
|
||||
```
|
||||
bin/kc.sh build --db postgres
|
||||
```
|
||||
|
||||
The usage of individual arguments is also required in Dockerfile run commands.
|
||||
|
||||
= Removed RegistrationProfile form action
|
||||
|
|
|
@ -28,17 +28,17 @@ public class ShortErrorMessageHandler implements IParameterExceptionHandler {
|
|||
UnmatchedArgumentException uae = (UnmatchedArgumentException) ex;
|
||||
|
||||
String[] unmatched = getUnmatchedPartsByOptionSeparator(uae,"=");
|
||||
String original = uae.getUnmatched().get(0);
|
||||
if (unmatched[0].equals(original)) {
|
||||
unmatched = getUnmatchedPartsByOptionSeparator(uae," ");
|
||||
}
|
||||
|
||||
|
||||
String cliKey = unmatched[0];
|
||||
|
||||
PropertyMapper<?> mapper = PropertyMappers.getMapper(cliKey);
|
||||
|
||||
if (mapper == null || !(cmd.getCommand() instanceof AbstractCommand)) {
|
||||
errorMessage = "Unknown option: '" + cliKey + "'";
|
||||
if (cliKey.split("\\s").length > 1) {
|
||||
errorMessage = "Option: '" + cliKey + "' is not expected to contain whitespace, please remove any unnecessary quoting/escaping";
|
||||
} else {
|
||||
errorMessage = "Unknown option: '" + cliKey + "'";
|
||||
}
|
||||
} else {
|
||||
AbstractCommand command = cmd.getCommand();
|
||||
if (!command.getOptionCategories().contains(mapper.getCategory())) {
|
||||
|
|
|
@ -55,7 +55,7 @@ public class OptionValidationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Launch({"start", "--db-pasword mytestpw"})
|
||||
@Launch({"start", "--db-pasword", "mytestpw"})
|
||||
public void failUnknownOptionWhitespaceSeparatorNotShowingValue(LaunchResult result) {
|
||||
CLIResult cliResult = (CLIResult) result;
|
||||
assertEquals("Unknown option: '--db-pasword'\n" +
|
||||
|
@ -80,4 +80,11 @@ public class OptionValidationTest {
|
|||
"Possible solutions: --db-driver, --db-url, --db-url-host, --db-url-database, --db-url-port, --db-url-properties, --db-username, --db-password, --db-schema, --db-pool-initial-size, --db-pool-min-size, --db-pool-max-size, --db\n" +
|
||||
"Try '" + KeycloakDistribution.SCRIPT_CMD + " start --help' for more information on the available options.", cliResult.getErrorOutput());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Launch({ "start", "--db postgres" })
|
||||
void failSingleParamWithSpace(LaunchResult result) {
|
||||
CLIResult cliResult = (CLIResult) result;
|
||||
cliResult.assertError("Option: '--db postgres' is not expected to contain whitespace, please remove any unnecessary quoting/escaping");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue