Skip to content

Commit ddf1943

Browse files
authored
Remove dangling spaces wherever found. (#127475) (#127612)
* Remove dandling spaces wherever found. This PR addresses #117067 , a report about unexpected spaces breaking message parsers built by customers. I used the regex `(\. \")(?![A-Z(a-z_0-9-;<%\/\.+ \t\n]+)` to detect such instances and clean up. In one case, a minor code improvement helps add optional spaces as necessary for a multi-sentence error message. * fix test * Update docs/changelog/127475.yaml * correct logic * fix test * fix tests * fix tests * fix tests * Update docs/changelog/127475.yaml * Update x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/action/TransportGetInferenceModelAction.java Co-authored-by: Slobodan Adamović <[email protected]> * Update libs/x-content/src/main/java/org/elasticsearch/xcontent/ObjectParser.java Co-authored-by: Slobodan Adamović <[email protected]> * correctly reference issue * Update docs/changelog/127475.yaml --------- Co-authored-by: Slobodan Adamović <[email protected]> (cherry picked from commit 94854b3)
1 parent 577a6f8 commit ddf1943

File tree

22 files changed

+49
-30
lines changed

22 files changed

+49
-30
lines changed

docs/changelog/127475.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 127475
2+
summary: Remove dangling spaces wherever found
3+
area: Security
4+
type: bug
5+
issues: []

libs/x-content/src/main/java/org/elasticsearch/xcontent/ObjectParser.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,11 @@ private void throwExpectedStartObject(XContentParser parser, XContentParser.Toke
333333

334334
private static void throwMissingRequiredFields(List<String[]> requiredFields) {
335335
final StringBuilder message = new StringBuilder();
336-
for (String[] fields : requiredFields) {
337-
message.append("Required one of fields ").append(Arrays.toString(fields)).append(", but none were specified. ");
336+
for (int i = 0; i < requiredFields.size(); i++) {
337+
if (i > 0) {
338+
message.append(" ");
339+
}
340+
message.append("Required one of fields ").append(Arrays.toString(requiredFields.get(i))).append(", but none were specified.");
338341
}
339342
throw new IllegalArgumentException(message.toString());
340343
}

libs/x-content/src/test/java/org/elasticsearch/xcontent/ObjectParserTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ public void testMultipleRequiredFieldSet() throws IOException {
10041004
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> objectParser.apply(parser, null));
10051005
assertThat(
10061006
e.getMessage(),
1007-
equalTo("Required one of fields [a, b], but none were specified. " + "Required one of fields [c, d], but none were specified. ")
1007+
equalTo("Required one of fields [a, b], but none were specified. " + "Required one of fields [c, d], but none were specified.")
10081008
);
10091009
}
10101010

server/src/main/java/org/elasticsearch/cluster/routing/allocation/shards/ShardsAvailabilityHealthIndicatorService.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ static void updateShardAllocationStatus(
299299
NAME,
300300
"increase_shard_limit_index_setting",
301301
"Elasticsearch isn't allowed to allocate some shards from these indices to any data nodes because each node has reached the index "
302-
+ "shard limit. ",
302+
+ "shard limit.",
303303
"Increase the values for the ["
304304
+ INDEX_TOTAL_SHARDS_PER_NODE_SETTING.getKey()
305305
+ "] index setting on each index or add more nodes to the target tiers.",
@@ -316,7 +316,7 @@ static void updateShardAllocationStatus(
316316
"increase_shard_limit_index_setting:tier:" + tier,
317317
"Elasticsearch isn't allowed to allocate some shards from these indices because each node in the ["
318318
+ tier
319-
+ "] tier has reached the index shard limit. ",
319+
+ "] tier has reached the index shard limit.",
320320
"Increase the values for the ["
321321
+ INDEX_TOTAL_SHARDS_PER_NODE_SETTING.getKey()
322322
+ "] index setting on each index or add more nodes to the target tiers.",
@@ -347,7 +347,7 @@ static void updateShardAllocationStatus(
347347
"increase_shard_limit_cluster_setting:tier:" + tier,
348348
"Elasticsearch isn't allowed to allocate some shards from these indices because each node in the ["
349349
+ tier
350-
+ "] tier has reached the cluster shard limit. ",
350+
+ "] tier has reached the cluster shard limit.",
351351
"Increase the values for the ["
352352
+ CLUSTER_TOTAL_SHARDS_PER_NODE_SETTING.getKey()
353353
+ "] cluster setting or add more nodes to the target tiers.",
@@ -395,7 +395,7 @@ static void updateShardAllocationStatus(
395395
NAME,
396396
"migrate_data_tiers_include_data",
397397
"Elasticsearch isn't allowed to allocate some shards from these indices to any nodes in the desired data tiers because the "
398-
+ "indices are configured with allocation filter rules that are incompatible with the nodes in this tier. ",
398+
+ "indices are configured with allocation filter rules that are incompatible with the nodes in this tier.",
399399
"Remove ["
400400
+ INDEX_ROUTING_INCLUDE_GROUP_PREFIX
401401
+ ".data] from the index settings or try migrating to data tiers by first stopping ILM [POST /_ilm/stop] and then using "

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/CommandLineHttpClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public void checkClusterHealthWithRetriesWaitingForCluster(String username, Secu
277277
checkClusterHealthWithRetriesWaitingForCluster(username, password, retries);
278278
return;
279279
} else {
280-
throw new IllegalStateException("Failed to determine the health of the cluster. ", e);
280+
throw new IllegalStateException("Failed to determine the health of the cluster.", e);
281281
}
282282
}
283283
final int responseStatus = response.getHttpStatus();

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/store/ReservedRolesStore.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ private static Map<String, RoleDescriptor> initializeReservedRoles() {
544544
+ "This role grants monitor_ml cluster privileges, read access to the .ml-notifications and .ml-anomalies* indices "
545545
+ "(which store machine learning results), and write access to .ml-annotations* indices. "
546546
+ "Machine learning users also need index privileges for source and destination indices "
547-
+ "and roles that grant access to Kibana. "
547+
+ "and roles that grant access to Kibana."
548548
)
549549
),
550550
entry(

x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static DeprecationIssue checkMultipleDataPaths(
213213
"Specifying multiple data paths is deprecated",
214214
"https://ela.st/es-deprecation-7-multiple-paths",
215215
"The [path.data] setting contains a list of paths. Specify a single path as a string. Use RAID or other system level "
216-
+ "features to utilize multiple disks. If multiple data paths are configured, the node will fail to start in 8.0. ",
216+
+ "features to utilize multiple disks. If multiple data paths are configured, the node will fail to start in 8.0.",
217217
false,
218218
null
219219
);
@@ -233,7 +233,7 @@ static DeprecationIssue checkDataPathsList(
233233
"Multiple data paths are not supported",
234234
"https://ela.st/es-deprecation-7-multiple-paths",
235235
"The [path.data] setting contains a list of paths. Specify a single path as a string. Use RAID or other system level "
236-
+ "features to utilize multiple disks. If multiple data paths are configured, the node will fail to start in 8.0. ",
236+
+ "features to utilize multiple disks. If multiple data paths are configured, the node will fail to start in 8.0.",
237237
false,
238238
null
239239
);

x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public void testMultipleDataPaths() {
112112
issue.getDetails(),
113113
equalTo(
114114
"The [path.data] setting contains a list of paths. Specify a single path as a string. Use RAID or other system level "
115-
+ "features to utilize multiple disks. If multiple data paths are configured, the node will fail to start in 8.0. "
115+
+ "features to utilize multiple disks. If multiple data paths are configured, the node will fail to start in 8.0."
116116
)
117117
);
118118
String url = "https://ela.st/es-deprecation-7-multiple-paths";
@@ -137,7 +137,7 @@ public void testDataPathsList() {
137137
issue.getDetails(),
138138
equalTo(
139139
"The [path.data] setting contains a list of paths. Specify a single path as a string. Use RAID or other system level "
140-
+ "features to utilize multiple disks. If multiple data paths are configured, the node will fail to start in 8.0. "
140+
+ "features to utilize multiple disks. If multiple data paths are configured, the node will fail to start in 8.0."
141141
)
142142
);
143143
String url = "https://ela.st/es-deprecation-7-multiple-paths";

x-pack/plugin/ent-search/src/test/java/org/elasticsearch/xpack/application/analytics/event/parser/event/AnalyticsEventParserTestCase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void testParsingWithMissingRequiredField() throws IOException {
8484

8585
try (XContentParser xContentParser = createXContentParser(json)) {
8686
Exception e = expectThrows(IllegalArgumentException.class, () -> parser().parse(xContentParser, context));
87-
assertEquals(Strings.format("Required one of fields [%s], but none were specified. ", field), e.getMessage());
87+
assertEquals(Strings.format("Required one of fields [%s], but none were specified.", field), e.getMessage());
8888
}
8989
}
9090
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/fulltext/QueryString.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public QueryString(
145145
name = "allow_wildcard",
146146
type = "boolean",
147147
valueHint = { "false", "true" },
148-
description = "If true, the query attempts to analyze wildcard terms in the query string. Defaults to false. "
148+
description = "If true, the query attempts to analyze wildcard terms in the query string. Defaults to false."
149149
),
150150
@MapParam.MapParamEntry(
151151
name = "analyzer",

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/action/BaseTransportInferenceAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ private ElasticsearchStatusException unsupportedStreamingTaskException(Request r
384384
}
385385

386386
private static ElasticsearchStatusException unknownServiceException(String service, String inferenceId) {
387-
return new ElasticsearchStatusException("Unknown service [{}] for model [{}]. ", RestStatus.BAD_REQUEST, service, inferenceId);
387+
return new ElasticsearchStatusException("Unknown service [{}] for model [{}]", RestStatus.BAD_REQUEST, service, inferenceId);
388388
}
389389

390390
private static ElasticsearchStatusException requestModelTaskTypeMismatchException(TaskType requested, TaskType expected) {

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/action/TransportGetInferenceModelAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ private void parseModels(List<UnparsedModel> unparsedModels, ActionListener<GetI
174174

175175
private ElasticsearchStatusException serviceNotFoundException(String service, String inferenceId) {
176176
throw new ElasticsearchStatusException(
177-
"Unknown service [{}] for inference endpoint [{}]. ",
177+
"Unknown service [{}] for inference endpoint [{}].",
178178
RestStatus.INTERNAL_SERVER_ERROR,
179179
service,
180180
inferenceId

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/action/BaseTransportInferenceActionTestCase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public void testMetricsAfterMissingService() {
171171

172172
verify(listener).onFailure(assertArg(e -> {
173173
assertThat(e, isA(ElasticsearchException.class));
174-
assertThat(e.getMessage(), is("Unknown service [" + serviceId + "] for model [" + inferenceId + "]. "));
174+
assertThat(e.getMessage(), is("Unknown service [" + serviceId + "] for model [" + inferenceId + "]"));
175175
assertThat(((ElasticsearchException) e).status(), is(RestStatus.BAD_REQUEST));
176176
}));
177177
verify(inferenceStats.inferenceDuration()).record(anyLong(), assertArg(attributes -> {

x-pack/plugin/security/cli/src/main/java/org/elasticsearch/xpack/security/cli/HttpCertificateCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ private static boolean askCertSigningRequest(Terminal terminal) {
817817

818818
terminal.println("A CSR is used when you want your certificate to be created by an existing");
819819
terminal.println("Certificate Authority (CA) that you do not control (that is, you don't have");
820-
terminal.println("access to the keys for that CA). ");
820+
terminal.println("access to the keys for that CA).");
821821
terminal.println("");
822822
terminal.println("If you are in a corporate environment with a central security team, then you");
823823
terminal.println("may have an existing Corporate CA that can generate your certificate for you.");

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/TokenService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,7 @@ private void innerRefresh(
13381338
);
13391339
} else {
13401340
logger.info(
1341-
"failed to update the original token document [{}] after all retries, the update result was [{}]. ",
1341+
"failed to update the original token document [{}] after all retries, the update result was [{}].",
13421342
tokenDoc.id(),
13431343
updateResponse.getResult()
13441344
);

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/esnative/tool/SetupPasswordTool.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ void checkElasticKeystorePasswordValid(Terminal terminal, Environment env) throw
398398
terminal.errorPrintln("");
399399
throw new UserException(
400400
ExitCodes.CONFIG,
401-
"Failed to establish SSL connection to elasticsearch at " + route.toString() + ". ",
401+
"Failed to establish SSL connection to elasticsearch at " + route.toString() + ".",
402402
e
403403
);
404404
} catch (IOException e) {
@@ -557,7 +557,7 @@ private void changeUserPassword(String user, SecureString password, Terminal ter
557557
terminal.errorPrintln("* Try running this tool again.");
558558
terminal.errorPrintln("* Try running with the --verbose parameter for additional messages.");
559559
terminal.errorPrintln("* Check the elasticsearch logs for additional error details.");
560-
terminal.errorPrintln("* Use the change password API manually. ");
560+
terminal.errorPrintln("* Use the change password API manually.");
561561
terminal.errorPrintln("");
562562
throw new UserException(ExitCodes.TEMP_FAILURE, "Failed to set password for user [" + user + "].");
563563
}

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/oidc/OpenIdConnectAuthenticator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public void authenticate(OpenIdConnectToken token, final ActionListener<JWTClaim
235235
// Don't wrap in a new ElasticsearchSecurityException
236236
listener.onFailure(e);
237237
} catch (Exception e) {
238-
listener.onFailure(new ElasticsearchSecurityException("Failed to consume the OpenID connect response. ", e));
238+
listener.onFailure(new ElasticsearchSecurityException("Failed to consume the OpenID connect response.", e));
239239
}
240240
}
241241

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/saml/SamlAuthenticator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private SamlAttributes authenticateResponse(Element element, Collection<String>
121121
logger.debug(
122122
"The Attribute Statements of SAML Response with ID [{}] contained no attributes and the SAML Assertion Subject "
123123
+ "did not contain a SAML NameID. Please verify that the Identity Provider configuration with regards to attribute "
124-
+ "release is correct. ",
124+
+ "release is correct.",
125125
response.getID()
126126
);
127127
throw samlException("Could not process any SAML attributes in {}", response.getElementQName());

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/store/FileRolesStore.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ static RoleDescriptor parseRoleDescriptor(
305305
Validation.Error validationError = Validation.Roles.validateRoleName(roleName, false);
306306
if (validationError != null) {
307307
logger.error(
308-
"invalid role definition [{}] in roles file [{}]. invalid role name - {}. skipping role... ",
308+
"invalid role definition [{}] in roles file [{}]. invalid role name - {}. skipping role...",
309309
roleName,
310310
path.toAbsolutePath(),
311311
validationError
@@ -392,7 +392,7 @@ private static RoleDescriptor checkDescriptor(
392392
Validation.Error validationError = Validation.Roles.validateRoleDescription(descriptor.getDescription());
393393
if (validationError != null) {
394394
logger.error(
395-
"invalid role definition [{}] in roles file [{}]. invalid description - {}. skipping role... ",
395+
"invalid role definition [{}] in roles file [{}]. invalid description - {}. skipping role...",
396396
roleName,
397397
path.toAbsolutePath(),
398398
validationError

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/tool/BaseRunAsSuperuserCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ private void checkClusterHealthWithRetries(
213213
try {
214214
response = client.execute("GET", clusterHealthUrl, username, password, () -> null, CommandLineHttpClient::responseBuilder);
215215
} catch (Exception e) {
216-
throw new UserException(ExitCodes.UNAVAILABLE, "Failed to determine the health of the cluster. ", e);
216+
throw new UserException(ExitCodes.UNAVAILABLE, "Failed to determine the health of the cluster.", e);
217217
}
218218
final int responseStatus = response.getHttpStatus();
219219
if (responseStatus != HttpURLConnection.HTTP_OK) {

x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/content/ObjectParser.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ private void throwFailedToParse(JsonParser parser, String currentFieldName, Exce
261261
private static void throwMissingRequiredFields(List<String[]> requiredFields) {
262262
final StringBuilder message = new StringBuilder();
263263
for (String[] fields : requiredFields) {
264-
message.append("Required one of fields ").append(Arrays.toString(fields)).append(", but none were specified. ");
264+
message.append("Required one of fields ").append(Arrays.toString(fields)).append(", but none were specified.");
265265
}
266266
throw new ParseException(message.toString());
267267
}

x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportStopTransformAction.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -467,24 +467,31 @@ private void waitForTransformStopped(
467467
return;
468468
} else {
469469
StringBuilder message = new StringBuilder();
470+
boolean lineAdded = false;
470471
if (persistentTaskIds.size() - stillRunningTasks.size() - exceptions.size() > 0) {
472+
message.append(optionalSpace(lineAdded));
471473
message.append("Successfully stopped [");
472474
message.append(persistentTaskIds.size() - stillRunningTasks.size() - exceptions.size());
473-
message.append("] transforms. ");
475+
message.append("] transforms.");
476+
lineAdded = true;
474477
}
475478

476479
if (exceptions.size() > 0) {
480+
message.append(optionalSpace(lineAdded));
477481
message.append("Could not stop the transforms ");
478482
message.append(exceptions.keySet());
479-
message.append(" as they were failed. Use force stop to stop the transforms. ");
483+
message.append(" as they were failed. Use force stop to stop the transforms.");
484+
lineAdded = true;
480485
}
481486

482487
if (stillRunningTasks.size() > 0) {
488+
message.append(optionalSpace(lineAdded));
483489
message.append("Could not stop the transforms ");
484490
message.append(stillRunningTasks);
485491
message.append(" as they timed out [");
486492
message.append(timeout.toString());
487493
message.append("].");
494+
lineAdded = true;
488495
}
489496

490497
listener.onFailure(new ElasticsearchStatusException(message.toString(), RestStatus.REQUEST_TIMEOUT));
@@ -542,4 +549,8 @@ static ActionListener<Response> cancelTransformTasksListener(
542549
}
543550
});
544551
}
552+
553+
private static String optionalSpace(boolean spaceNeeded) {
554+
return spaceNeeded ? " " : "";
555+
}
545556
}

0 commit comments

Comments
 (0)