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) {
130
130
}
131
131
}
132
132
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
+ }
133
140
}
Original file line number Diff line number Diff line change @@ -152,5 +152,24 @@ public void constructorWhenRequiredAddressIsEmptyThenThrowsIllegalArgumentExcept
152
152
assertThatIllegalArgumentException ().isThrownBy (() -> new IpAddressMatcher ("" ))
153
153
.withMessage ("ipAddress cannot be empty" );
154
154
}
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
+ }
155
174
156
175
}
You can’t perform that action at this time.
0 commit comments