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

fix: wildcard in allowNavigation #3833

Merged
merged 2 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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