Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
c306e031
Commit
c306e031
authored
Oct 15, 2018
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support '-' in endpoint names
Update the `EndpointId` constraints to allow '-' in names. Closes gh-14773
parent
d8b96856
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
14 deletions
+41
-14
EndpointId.java
...org/springframework/boot/actuate/endpoint/EndpointId.java
+21
-6
EndpointIdTests.java
...pringframework/boot/actuate/endpoint/EndpointIdTests.java
+20
-8
No files found.
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/EndpointId.java
View file @
c306e031
...
...
@@ -23,30 +23,44 @@ import org.springframework.util.Assert;
/**
* An identifier for an actuator endpoint. Endpoint IDs may contain only letters, numbers
*
and {@code '.'}. They must begin with a lower-case letter. Case is ignored when
* comparing endpoint IDs.
*
{@code '.'} and {@code '-'}. They must begin with a lower-case letter. Case and syntax
* c
haracters are ignored when c
omparing endpoint IDs.
*
* @author Phillip Webb
* @since 2.0.6
*/
public
final
class
EndpointId
{
private
static
final
Pattern
VALID_CHARS
=
Pattern
.
compile
(
"[a-zA-Z0-9\\.]+"
);
private
static
final
Pattern
VALID_CHARS
=
Pattern
.
compile
(
"[a-zA-Z0-9\\.
\\-
]+"
);
private
final
String
value
;
private
final
String
lowerCaseValue
;
private
final
String
lowerCaseAlphaNumeric
;
private
EndpointId
(
String
value
)
{
Assert
.
hasText
(
value
,
"Value must not be empty"
);
Assert
.
isTrue
(
VALID_CHARS
.
matcher
(
value
).
matches
(),
"Value must
be alpha-numeric or '.'
"
);
"Value must
only contain valid chars
"
);
Assert
.
isTrue
(!
Character
.
isDigit
(
value
.
charAt
(
0
)),
"Value must not start with a number"
);
Assert
.
isTrue
(!
Character
.
isUpperCase
(
value
.
charAt
(
0
)),
"Value must not start with an uppercase letter"
);
this
.
value
=
value
;
this
.
lowerCaseValue
=
value
.
toLowerCase
(
Locale
.
ENGLISH
);
this
.
lowerCaseAlphaNumeric
=
getAlphaNumerics
(
this
.
lowerCaseValue
);
}
private
String
getAlphaNumerics
(
String
value
)
{
StringBuilder
result
=
new
StringBuilder
(
value
.
length
());
for
(
int
i
=
0
;
i
<
value
.
length
();
i
++)
{
char
ch
=
value
.
charAt
(
i
);
if
(
ch
>=
'a'
&&
ch
<=
'z'
||
ch
>=
'0'
&&
ch
<=
'9'
)
{
result
.
append
(
ch
);
}
}
return
result
.
toString
();
}
@Override
...
...
@@ -57,12 +71,13 @@ public final class EndpointId {
if
(
obj
==
null
||
getClass
()
!=
obj
.
getClass
())
{
return
false
;
}
return
toLowerCaseString
().
equals
(((
EndpointId
)
obj
).
toLowerCaseString
());
return
this
.
lowerCaseAlphaNumeric
.
equals
(((
EndpointId
)
obj
).
lowerCaseAlphaNumeric
);
}
@Override
public
int
hashCode
()
{
return
t
oLowerCaseString
()
.
hashCode
();
return
t
his
.
lowerCaseAlphaNumeric
.
hashCode
();
}
/**
...
...
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/EndpointIdTests.java
View file @
c306e031
...
...
@@ -47,16 +47,16 @@ public class EndpointIdTests {
}
@Test
public
void
ofWhenContains
Dash
ThrowsException
()
{
public
void
ofWhenContains
InvalidChar
ThrowsException
()
{
this
.
thrown
.
expect
(
IllegalArgumentException
.
class
);
this
.
thrown
.
expectMessage
(
"Value must
be alpha-numeric
"
);
EndpointId
.
of
(
"foo
-
bar"
);
this
.
thrown
.
expectMessage
(
"Value must
only contain valid chars
"
);
EndpointId
.
of
(
"foo
/
bar"
);
}
@Test
public
void
ofWhenHasBadCharThrowsException
()
{
this
.
thrown
.
expect
(
IllegalArgumentException
.
class
);
this
.
thrown
.
expectMessage
(
"Value must
be alpha-numeric
"
);
this
.
thrown
.
expectMessage
(
"Value must
only contain valid chars
"
);
EndpointId
.
of
(
"foo!bar"
);
}
...
...
@@ -82,13 +82,25 @@ public class EndpointIdTests {
assertThat
(
endpointId
.
toString
()).
isEqualTo
(
"foo.bar"
);
}
@Test
public
void
ofWhenContainsDashIsValid
()
{
// Ideally we wouldn't support this but there are existing endpoints using the
// pattern. See gh-14773
EndpointId
endpointId
=
EndpointId
.
of
(
"foo-bar"
);
assertThat
(
endpointId
.
toString
()).
isEqualTo
(
"foo-bar"
);
}
@Test
public
void
equalsAndHashCode
()
{
EndpointId
one
=
EndpointId
.
of
(
"foobar"
);
EndpointId
two
=
EndpointId
.
of
(
"fooBar"
);
EndpointId
three
=
EndpointId
.
of
(
"barfoo"
);
EndpointId
one
=
EndpointId
.
of
(
"foobar1"
);
EndpointId
two
=
EndpointId
.
of
(
"fooBar1"
);
EndpointId
three
=
EndpointId
.
of
(
"foo-bar1"
);
EndpointId
four
=
EndpointId
.
of
(
"foo.bar1"
);
EndpointId
five
=
EndpointId
.
of
(
"barfoo1"
);
EndpointId
six
=
EndpointId
.
of
(
"foobar2"
);
assertThat
(
one
.
hashCode
()).
isEqualTo
(
two
.
hashCode
());
assertThat
(
one
).
isEqualTo
(
one
).
isEqualTo
(
two
).
isNotEqualTo
(
three
);
assertThat
(
one
).
isEqualTo
(
one
).
isEqualTo
(
two
).
isEqualTo
(
two
).
isEqualTo
(
three
)
.
isEqualTo
(
four
).
isNotEqualTo
(
five
).
isNotEqualTo
(
six
);
}
@Test
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment