Add hasText assertion to IpAddressMatcher constructor

Issue gh-15527

(cherry picked from commit 3a298196512de5f3002707e2af8298d650033df7)
This commit is contained in:
Steve Riesenberg 2024-11-14 23:12:51 -06:00
parent 554df6fab6
commit ddf4542a9e
No known key found for this signature in database
GPG Key ID: 3D0169B18AB8F0A9
2 changed files with 15 additions and 0 deletions

View File

@ -50,6 +50,7 @@ public final class IpAddressMatcher implements RequestMatcher {
* come. * come.
*/ */
public IpAddressMatcher(String ipAddress) { public IpAddressMatcher(String ipAddress) {
Assert.hasText(ipAddress, "ipAddress cannot be empty");
assertNotHostName(ipAddress); assertNotHostName(ipAddress);
if (ipAddress.indexOf('/') > 0) { if (ipAddress.indexOf('/') > 0) {
String[] addressAndMask = StringUtils.split(ipAddress, "/"); String[] addressAndMask = StringUtils.split(ipAddress, "/");

View File

@ -139,4 +139,18 @@ public class IpAddressMatcherTests {
assertThat(this.v4matcher.matches((String) null)).isFalse(); assertThat(this.v4matcher.matches((String) null)).isFalse();
} }
// gh-15527
@Test
public void constructorWhenRequiredAddressIsNullThenThrowsIllegalArgumentException() {
assertThatIllegalArgumentException().isThrownBy(() -> new IpAddressMatcher(null))
.withMessage("ipAddress cannot be empty");
}
// gh-15527
@Test
public void constructorWhenRequiredAddressIsEmptyThenThrowsIllegalArgumentException() {
assertThatIllegalArgumentException().isThrownBy(() -> new IpAddressMatcher(""))
.withMessage("ipAddress cannot be empty");
}
} }