Skip to content

Commit adfbbcc

Browse files
m7stocksnicoll
authored andcommitted
Simplify validation pattern of EndpointId
See gh-19584
1 parent bdffa86 commit adfbbcc

File tree

2 files changed

+10
-4
lines changed
  • spring-boot-project/spring-boot-actuator/src

2 files changed

+10
-4
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/EndpointId.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,9 +40,9 @@ public final class EndpointId {
4040

4141
private static Set<String> loggedWarnings = new HashSet<>();
4242

43-
private static final Pattern VALID_PATTERN = Pattern.compile("[a-zA-Z0-9\\.\\-]+");
43+
private static final Pattern VALID_PATTERN = Pattern.compile("[a-zA-Z0-9.-]+");
4444

45-
private static final Pattern WARNING_PATTERN = Pattern.compile("[\\.\\-]+");
45+
private static final Pattern WARNING_PATTERN = Pattern.compile("[.-]+");
4646

4747
private final String value;
4848

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/EndpointIdTests.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -51,6 +51,12 @@ public void ofWhenContainsSlashThrowsException() {
5151
.withMessage("Value must only contain valid chars");
5252
}
5353

54+
@Test
55+
public void ofWhenContainsBackslashThrowsException() {
56+
assertThatIllegalArgumentException().isThrownBy(() -> EndpointId.of("foo\\bar"))
57+
.withMessage("Value must only contain valid chars");
58+
}
59+
5460
@Test
5561
public void ofWhenHasBadCharThrowsException() {
5662
assertThatIllegalArgumentException().isThrownBy(() -> EndpointId.of("foo!bar"))

0 commit comments

Comments
 (0)