Given the following parameterized test, the first 3 URLs match, but the last one (http://alice:secret@localhost:) does not.
class NohttpTests {
// Copied from io.spring.nohttp.RegexHttpMatcher
private final Pattern pattern = Pattern.compile(
"\\b(http\\\\?://[-a-zA-Z0-9+&@/%?=~_|!:,.;]*[-a-zA-Z0-9+&@/%=~_|])");
@ParameterizedTest
@ValueSource(strings = {
"http://localhost",
"http://alice:secret@localhost",
"http://alice:secret@localhost:80",
"http://alice:secret@localhost:"
})
void test(String url) {
assertThat(pattern.matcher(url)).as(url).matches();
}
}
Note that the last one was taken from Java source code which builds the URL programmatically as follows.
String url = "http://alice:secret@localhost:" + port + "/resource";
Given the following parameterized test, the first 3 URLs match, but the last one (
http://alice:secret@localhost:) does not.Note that the last one was taken from Java source code which builds the URL programmatically as follows.