Skip to content

Commit ddf4542

Browse files
committed
Add hasText assertion to IpAddressMatcher constructor
Issue gh-15527 (cherry picked from commit 3a29819)
1 parent 554df6f commit ddf4542

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

web/src/main/java/org/springframework/security/web/util/matcher/IpAddressMatcher.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public final class IpAddressMatcher implements RequestMatcher {
5050
* come.
5151
*/
5252
public IpAddressMatcher(String ipAddress) {
53+
Assert.hasText(ipAddress, "ipAddress cannot be empty");
5354
assertNotHostName(ipAddress);
5455
if (ipAddress.indexOf('/') > 0) {
5556
String[] addressAndMask = StringUtils.split(ipAddress, "/");

web/src/test/java/org/springframework/security/web/util/matcher/IpAddressMatcherTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,18 @@ public void matchesWhenAddressIsNullThenFalse() {
139139
assertThat(this.v4matcher.matches((String) null)).isFalse();
140140
}
141141

142+
// gh-15527
143+
@Test
144+
public void constructorWhenRequiredAddressIsNullThenThrowsIllegalArgumentException() {
145+
assertThatIllegalArgumentException().isThrownBy(() -> new IpAddressMatcher(null))
146+
.withMessage("ipAddress cannot be empty");
147+
}
148+
149+
// gh-15527
150+
@Test
151+
public void constructorWhenRequiredAddressIsEmptyThenThrowsIllegalArgumentException() {
152+
assertThatIllegalArgumentException().isThrownBy(() -> new IpAddressMatcher(""))
153+
.withMessage("ipAddress cannot be empty");
154+
}
155+
142156
}

0 commit comments

Comments
 (0)