Skip to content

Commit

Permalink
fix: wildcard in allowNavigation (#3833)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Nov 20, 2020
1 parent 4f9789d commit de1eac8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public boolean matches(String host) {
List<String> hostParts = Util.splitAndReverse(host);
int hostSize = hostParts.size();
int maskSize = maskParts.size();
if(hostSize != maskSize) {
if(maskSize > 1 && hostSize != maskSize) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public void testParser() {

@Test
public void testAny() {
HostMask mask = HostMask.Any.parse("*", "*.example.org", "example.org");
assertTrue(mask.matches("org"));
HostMask mask = HostMask.Any.parse("*.example.org", "example.org");
assertFalse(mask.matches("org"));
assertTrue(mask.matches("example.org"));
assertTrue(mask.matches("www.example.org"));
assertFalse(mask.matches("imap.mail.example.org"));
Expand All @@ -27,6 +27,17 @@ public void testAny() {
assertFalse(mask.matches(null));
}

@Test
public void testAnyWildcard() {
HostMask mask = HostMask.Any.parse("*");
assertTrue(mask.matches("org"));
assertTrue(mask.matches("example.org"));
assertTrue(mask.matches("www.example.org"));
assertTrue(mask.matches("imap.mail.example.org"));
assertTrue(mask.matches("another.org"));
assertTrue(mask.matches("www.another.org"));
assertFalse(mask.matches(null));
}

@Test
public void testSimple() {
Expand All @@ -46,7 +57,7 @@ public void testSimpleExample1() {
@Test
public void testSimpleExample2() {
HostMask mask = HostMask.Simple.parse("*");
assertFalse("Single star does not match with 2nd level domain", mask.matches("example.org"));
assertTrue("Single star matches everything", mask.matches("example.org"));
}

@Test
Expand Down
4 changes: 4 additions & 0 deletions ios/Capacitor/Capacitor/CAPBridgeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,10 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr
}

func matchHost(host: String, pattern: String) -> Bool {
if pattern == "*" {
return true
}

var host = host.split(separator: ".")
var pattern = pattern.split(separator: ".")

Expand Down

0 comments on commit de1eac8

Please sign in to comment.