Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RegexHttpMatcher does match against http URL fragment missing port #65

Open
sbrannen opened this issue Sep 25, 2024 · 0 comments
Open
Assignees

Comments

@sbrannen
Copy link

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";
@rwinch rwinch self-assigned this Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants