mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-07 15:50:57 +03:00
Fix escaping in WildcardHostMatcher (#382)
* Escape '[' and ']' in WildcardHostMatcher * Anchoring regex to match entire string (Fixes #381)
This commit is contained in:
@@ -135,7 +135,7 @@ public class KnownHostMatchers {
|
||||
private final Pattern pattern;
|
||||
|
||||
public WildcardHostMatcher(String hostEntry) {
|
||||
this.pattern = Pattern.compile(hostEntry.replace(".", "\\.").replace("*", ".*").replace("?", "."));
|
||||
this.pattern = Pattern.compile("^" + hostEntry.replace("[", "\\[").replace("]", "\\]").replace(".", "\\.").replace("*", ".*").replace("?", ".") + "$");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -360,7 +360,7 @@ public class OpenSSHKnownHosts
|
||||
}
|
||||
|
||||
protected String getHostPart() {
|
||||
return hostPart;
|
||||
return hostPart;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,11 @@ class KnownHostMatchersSpec extends Specification {
|
||||
"aaa.b??.com" | "aaa.bccd.com" | false
|
||||
"|1|F1E1KeoE/eEWhi10WpGv4OdiO6Y=|3988QV0VE8wmZL7suNrYQLITLCg=" | "192.168.1.61" | true
|
||||
"|1|F1E1KeoE/eEWhi10WpGv4OdiO6Y=|3988QV0VE8wmZL7suNrYQLITLCg=" | "192.168.2.61" | false
|
||||
"[aaa.bbb.com]:2222" | "aaa.bbb.com" | false
|
||||
"[aaa.bbb.com]:2222" | "[aaa.bbb.com]:2222" | true
|
||||
"[aaa.?bb.com]:2222" | "[aaa.dbb.com]:2222" | true
|
||||
"[aaa.?xb.com]:2222" | "[aaa.dbb.com]:2222" | false
|
||||
"[*.bbb.com]:2222" | "[aaa.bbb.com]:2222" | true
|
||||
yesno = match ? "" : "no"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user