diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/Job.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/Job.java index cd8392616f1..2b12806fd7b 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/Job.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/Job.java @@ -718,7 +718,7 @@ public class Job extends AbstractDiffable implements Writeable, ToXContent id = this.id; } else { // Base64 UUIDs are not necessarily valid job IDs - id = "auto-" + UUIDs.base64UUID().toLowerCase(Locale.ROOT).replaceAll("/\\+=", "_"); + id = "auto-" + UUIDs.base64UUID().toLowerCase(Locale.ROOT).replaceAll("[/+=-]", "_"); if (id.endsWith("_")) { // Job IDs cannot end with underscores id = id.substring(0, id.length() - 1) + "z"; @@ -739,7 +739,7 @@ public class Job extends AbstractDiffable implements Writeable, ToXContent throw new IllegalArgumentException(Messages.getMessage(Messages.JOB_CONFIG_ID_TOO_LONG, MAX_JOB_ID_LENGTH)); } if (!PrelertStrings.isValidId(id)) { - throw new IllegalArgumentException(Messages.getMessage(Messages.INVALID_ID, ID.getPreferredName())); + throw new IllegalArgumentException(Messages.getMessage(Messages.INVALID_ID, ID.getPreferredName(), id)); } if (Strings.isNullOrEmpty(indexName)) { diff --git a/elasticsearch/src/main/resources/org/elasticsearch/xpack/prelert/job/messages/prelert_messages.properties b/elasticsearch/src/main/resources/org/elasticsearch/xpack/prelert/job/messages/prelert_messages.properties index 1a3c13a9e98..9300c01decc 100644 --- a/elasticsearch/src/main/resources/org/elasticsearch/xpack/prelert/job/messages/prelert_messages.properties +++ b/elasticsearch/src/main/resources/org/elasticsearch/xpack/prelert/job/messages/prelert_messages.properties @@ -10,7 +10,7 @@ datastore.error.deleting = Error deleting index ''{0}'' datastore.error.deleting.missing.index = Cannot delete job - no index with id ''{0}'' in the database datastore.error.executing.script = Error executing script ''{0}'' -invalid.id = Invalid {0}; must be lowercase alphanumeric, may contain hyphens or underscores, may not start with underscore +invalid.id = Invalid {0}; ''{1}'' must be lowercase alphanumeric, may contain hyphens or underscores, may not start with underscore license.limit.detectors = Cannot create new job - your license limits you to {0,number,integer} detector(s), but you have configured {1,number,integer}. license.limit.detectors.reactivate = Cannot reactivate job with id ''{0}'' - your license limits you to {1,number,integer} concurrently running detectors. You must close a job before you can reactivate another. diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/JobTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/JobTests.java index 680b81d953c..0bc1dac5783 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/JobTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/JobTests.java @@ -242,9 +242,9 @@ public class JobTests extends AbstractSerializingTestCase { public void testCheckValidId_ProhibitedChars() { String invalidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()+?\"'~±/\\[]{},<>="; Job.Builder builder = buildJobBuilder("foo"); - String errorMessage = Messages.getMessage(Messages.INVALID_ID, Job.ID.getPreferredName()); for (char c : invalidChars.toCharArray()) { builder.setId(Character.toString(c)); + String errorMessage = Messages.getMessage(Messages.INVALID_ID, Job.ID.getPreferredName(), Character.toString(c)); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, builder::build); assertEquals(errorMessage, e.getMessage()); } @@ -252,14 +252,14 @@ public class JobTests extends AbstractSerializingTestCase { public void testCheckValidId_startsWithUnderscore() { Job.Builder builder = buildJobBuilder("_foo"); - String errorMessage = Messages.getMessage(Messages.INVALID_ID, Job.ID.getPreferredName()); + String errorMessage = Messages.getMessage(Messages.INVALID_ID, Job.ID.getPreferredName(), "_foo"); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, builder::build); assertEquals(errorMessage, e.getMessage()); } public void testCheckValidId_endsWithUnderscore() { Job.Builder builder = buildJobBuilder("foo_"); - String errorMessage = Messages.getMessage(Messages.INVALID_ID, Job.ID.getPreferredName()); + String errorMessage = Messages.getMessage(Messages.INVALID_ID, Job.ID.getPreferredName(), "foo_"); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, builder::build); assertEquals(errorMessage, e.getMessage()); }