Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@
*
* @author Luke Taylor
* @author Steve Riesenberg
* @author Andrey Litvitski
* @since 3.0.2
*/
public final class IpAddressMatcher implements RequestMatcher {

private static Pattern IPV4 = Pattern.compile("\\d{0,3}.\\d{0,3}.\\d{0,3}.\\d{0,3}(/\\d{0,3})?");
private static Pattern IPV4 = Pattern.compile("^\\d{1,3}(?:\\.\\d{1,3}){0,3}(?:/\\d{1,2})?$");

private final InetAddress requiredAddress;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

/**
* @author Luke Taylor
* @author Andrey Litvitski
*/
public class IpAddressMatcherTests {

Expand Down Expand Up @@ -167,4 +168,12 @@ public void toStringWhenOnlyIpIsProvidedThenReturnsIpAddressOnly() {
assertThat(matcher.toString()).hasToString("IpAddress [127.0.0.1]");
}

// gh-17499
@Test
public void constructorRejectsInvalidIpv4WithX() {
String badIp = "10x1x1x1";
assertThatIllegalArgumentException().isThrownBy(() -> new IpAddressMatcher(badIp))
.withMessage("ipAddress 10x1x1x1 doesn't look like an IP Address. Is it a host name?");
}

}