File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
main/java/org/springframework/security/web/util/matcher
test/java/org/springframework/security/web/util/matcher Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -130,4 +130,11 @@ private InetAddress parseAddress(String address) {
130130 }
131131 }
132132
133+ @ Override
134+ public String toString () {
135+ String hostAddress = this .requiredAddress .getHostAddress ();
136+ return (this .nMaskBits < 0 )
137+ ? "IpAddressMatcher[" + hostAddress + "]"
138+ : "IpAddressMatcher[" + hostAddress + "/" + this .nMaskBits + "]" ;
139+ }
133140}
Original file line number Diff line number Diff line change @@ -152,5 +152,24 @@ public void constructorWhenRequiredAddressIsEmptyThenThrowsIllegalArgumentExcept
152152 assertThatIllegalArgumentException ().isThrownBy (() -> new IpAddressMatcher ("" ))
153153 .withMessage ("ipAddress cannot be empty" );
154154 }
155+ // gh-16795
156+ @ Test
157+ public void toStringWhenCidrIsProvidedThenReturnsIpAddressWithCidr () {
158+ IpAddressMatcher matcher = new IpAddressMatcher ("192.168.1.0/24" );
159+
160+ String result = matcher .toString ();
161+
162+ assertThat (result ).isEqualTo ("IpAddressMatcher[192.168.1.0/24]" );
163+ }
164+
165+ // gh-16795
166+ @ Test
167+ public void toStringWhenOnlyIpIsProvidedThenReturnsIpAddressOnly () {
168+ IpAddressMatcher matcher = new IpAddressMatcher ("127.0.0.1" );
169+
170+ String result = matcher .toString ();
171+
172+ assertThat (result ).isEqualTo ("IpAddressMatcher[127.0.0.1]" );
173+ }
155174
156175}
You can’t perform that action at this time.
0 commit comments