Skip to content

Commit

Permalink
allow full part match
Browse files Browse the repository at this point in the history
  • Loading branch information
danthe1st committed Mar 1, 2024
1 parent 6b00a60 commit 2433397
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*.crt
*.pem
.secret
ignoredHosts.txt
intercept.yaml

# Created by https://www.toptal.com/developers/gitignore/api/eclipse,maven,java,intellij+all
# Edit at https://www.toptal.com/developers/gitignore?templates=eclipse,maven,java,intellij+all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ private boolean doesMatchPart(String hostname) {
}

int index = 0;
while((index = hostname.indexOf('.', index) + 1) != 0 && index < hostname.length()){
do{
if(hostParts.contains(hostname.substring(index))){
return true;
}
}
}while((index = hostname.indexOf('.', index) + 1) != 0 && index < hostname.length());

return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ void testExactMatch() {
assertFalse(matcher.matches("github.com"));
}

@Test
void testEmptyPartMatch() {
HostMatcher matcher = new HostMatcher(
Collections.emptySet(),
Set.of(""),
Collections.emptySet()
);
assertFalse(matcher.matches("localhost"));
}

@Test
void testPartMatch() {
HostMatcher matcher = new HostMatcher(
Expand All @@ -31,7 +41,7 @@ void testPartMatch() {
assertTrue(matcher.matches("host.example.com"));
assertTrue(matcher.matches(".example.com"));
assertFalse(matcher.matches("host.github.com"));
assertFalse(matcher.matches("example.com"));
assertTrue(matcher.matches("example.com"));
assertFalse(matcher.matches("example.com."));
assertFalse(matcher.matches(""));
assertFalse(matcher.matches("."));
Expand Down

0 comments on commit 2433397

Please sign in to comment.