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
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) {
130
130
}
131
131
}
132
132
133
+ @ Override
134
+ public String toString () {
135
+ String hostAddress = this .requiredAddress .getHostAddress ();
136
+ return (this .nMaskBits < 0 ) ? "IpAddress [" + hostAddress + "]"
137
+ : "IpAddress [" + hostAddress + "/" + this .nMaskBits + "]" ;
138
+ }
139
+
133
140
}
Original file line number Diff line number Diff line change @@ -153,4 +153,18 @@ public void constructorWhenRequiredAddressIsEmptyThenThrowsIllegalArgumentExcept
153
153
.withMessage ("ipAddress cannot be empty" );
154
154
}
155
155
156
+ // gh-16795
157
+ @ Test
158
+ public void toStringWhenCidrIsProvidedThenReturnsIpAddressWithCidr () {
159
+ IpAddressMatcher matcher = new IpAddressMatcher ("192.168.1.0/24" );
160
+ assertThat (matcher .toString ()).hasToString ("IpAddress [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 ("IpAddress [127.0.0.1]" );
168
+ }
169
+
156
170
}
You can’t perform that action at this time.
0 commit comments