Skip to content

RegexHttpMatcher does match against http URL fragment missing port #65

@sbrannen

Description

@sbrannen

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";

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions