@@ -166,20 +166,26 @@ private Set<StandardConfigDataReference> getProfileSpecificReferences(ConfigData
166166 }
167167
168168 private void validateProfiles (Profiles profiles ) {
169- Pattern validProfilePattern = Pattern .compile ("^[a-zA-Z0-9_\\ -]+$" );
170- Assert .notNull (profiles , "Profiles must not be null" );
171169 for (String profile : profiles ) {
172- Assert .notNull (profile , "Profile must not be null" );
173- Assert .hasText (profile , "Profile must not be empty" );
174- Assert .state (!profile .startsWith ("-" ) && !profile .startsWith ("_" ),
175- () -> String .format ("Invalid profile '%s': must not start with '-' or '_'" , profile ));
176- Assert .state (!profile .endsWith ("-" ) && !profile .endsWith ("_" ),
177- () -> String .format ("Invalid profile '%s': must not end with '-' or '_'" , profile ));
178- Assert .state (validProfilePattern .matcher (profile ).matches (), () -> String
179- .format ("Invalid profile '%s': must only contain alphanumeric characters, '-', or '_'" , profile ));
170+ validateProfile (profile );
180171 }
181172 }
182173
174+ private void validateProfile (String profile ) {
175+ Assert .notNull (profile , "Profile must not be null" );
176+ Assert .hasText (profile , "Profile must not be empty" );
177+ Assert .state (!profile .startsWith ("-" ) && !profile .startsWith ("_" ),
178+ () -> String .format ("Invalid profile '%s': must not start with '-' or '_'" , profile ));
179+ Assert .state (!profile .endsWith ("-" ) && !profile .endsWith ("_" ),
180+ () -> String .format ("Invalid profile '%s': must not end with '-' or '_'" , profile ));
181+ profile .codePoints ().forEach ((codePoint ) -> {
182+ if (codePoint == '-' || codePoint == '_' || Character .isLetterOrDigit (codePoint )) {
183+ return ;
184+ }
185+ throw new IllegalStateException (String .format ("Invalid profile '%s': must contain only letters or digits or '-' or '_'" , profile ));
186+ });
187+ }
188+
183189 private String getResourceLocation (ConfigDataLocationResolverContext context ,
184190 ConfigDataLocation configDataLocation ) {
185191 String resourceLocation = configDataLocation .getNonPrefixedValue (PREFIX );
0 commit comments