File tree Expand file tree Collapse file tree 2 files changed +21
-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 +21
-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 ) ? "IpAddressMatcher[" + hostAddress + "]"
137+ : "IpAddressMatcher[" + hostAddress + "/" + this .nMaskBits + "]" ;
138+ }
139+
133140}
Original file line number Diff line number Diff line change @@ -153,4 +153,18 @@ public void constructorWhenRequiredAddressIsEmptyThenThrowsIllegalArgumentExcept
153153 .withMessage ("ipAddress cannot be empty" );
154154 }
155155
156+ // gh-16795
157+ @ Test
158+ public void toStringWhenCidrIsProvidedThenReturnsIpAddressWithCidr () {
159+ IpAddressMatcher matcher = new IpAddressMatcher ("192.168.1.0/24" );
160+ assertThat (matcher .toString ()).hasToString ("IpAddressMatcher[192.168.1.0/24]" );
161+ }
162+
163+ // gh-16795
164+ @ Test
165+ public void toStringWhenOnlyIpIsProvidedThenReturnsIpAddressOnly () {
166+ IpAddressMatcher matcher = new IpAddressMatcher ("127.0.0.1" );
167+ assertThat (matcher .toString ()).hasToString ("IpAddressMatcher[127.0.0.1]" );
168+ }
169+
156170}
You can’t perform that action at this time.
0 commit comments