File tree Expand file tree Collapse file tree 1 file changed +4
-11
lines changed
core/src/main/java/io/cloudevents/core/impl Expand file tree Collapse file tree 1 file changed +4
-11
lines changed Original file line number Diff line number Diff line change 30
30
import java .time .OffsetDateTime ;
31
31
import java .util .HashMap ;
32
32
import java .util .Map ;
33
+ import java .util .regex .Pattern ;
33
34
34
35
import static io .cloudevents .core .v03 .CloudEventV03 .SPECVERSION ;
35
36
36
37
public abstract class BaseCloudEventBuilder <SELF extends BaseCloudEventBuilder <SELF , T >, T extends CloudEvent > implements CloudEventBuilder {
37
38
38
39
// This is a little trick for enabling fluency
39
40
private final SELF self ;
41
+ private static final Pattern EXTENSION_NAME_PATTERN = Pattern .compile ("^([\\ da-z])+$" );
40
42
41
43
protected CloudEventData data ;
42
44
protected Map <String , Object > extensions = new HashMap <>();
@@ -213,19 +215,10 @@ protected static IllegalStateException createMissingAttributeException(String at
213
215
*
214
216
* @param name the extension name
215
217
* @return true if extension name is valid, false otherwise
216
- * @see <a href="https://github.com/cloudevents/spec/blob/master/ spec.md#attribute- naming-convention ">attribute-naming-convention </a>
218
+ * @see <a href="https://github.com/cloudevents/spec/blob/main/cloudevents/ spec.md#naming-conventions ">attribute-naming-conventions </a>
217
219
*/
218
220
private static boolean isValidExtensionName (String name ) {
219
- for (int i = 0 ; i < name .length (); i ++) {
220
- if (!isValidChar (name .charAt (i ))) {
221
- return false ;
222
- }
223
- }
224
- return true ;
225
- }
226
-
227
- private static boolean isValidChar (char c ) {
228
- return (c >= 'a' && c <= 'z' ) || (c >= '0' && c <= '9' );
221
+ return EXTENSION_NAME_PATTERN .matcher (name ).matches ();
229
222
}
230
223
231
224
protected void requireValidAttributeWrite (String name ) {
You can’t perform that action at this time.
0 commit comments