Skip to content

Commit

Permalink
fix(android): load local assets when using wildcard on allowNavigation (
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Nov 23, 2020
1 parent de1eac8 commit 66f2efb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 18 additions & 2 deletions android/capacitor/src/main/java/com/getcapacitor/Bridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public Bridge(Activity context, WebView webView, List<Class<? extends Plugin>> i
}

private void loadWebView() {
appUrlConfig = this.config.getString("server.url");
appUrlConfig = this.getServerUrl();
String[] appAllowNavigationConfig = this.config.getArray("server.allowNavigation");

ArrayList<String> authorities = new ArrayList<String>();
Expand All @@ -182,7 +182,7 @@ private void loadWebView() {
}
this.appAllowNavigationMask = HostMask.Parser.parse(appAllowNavigationConfig);

String authority = this.config.getString("server.hostname", "localhost");
String authority = this.getHost();
authorities.add(authority);

String scheme = this.getScheme();
Expand Down Expand Up @@ -341,6 +341,22 @@ public String getScheme() {
return this.config.getString("server.androidScheme", CAPACITOR_HTTP_SCHEME);
}

/**
* Get host name that is used to serve content
* @return
*/
public String getHost() {
return this.config.getString("server.hostname", "localhost");
}

/**
* Get the server url that is used to serve content
* @return
*/
public String getServerUrl() {
return this.config.getString("server.url");
}

public CapConfig getConfig() {
return this.config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public WebResourceResponse shouldInterceptRequest(WebResourceRequest request) {
return null;
}

if (isLocalFile(loadingUrl) || (bridge.getConfig().getString("server.url") == null && !bridge.getAppAllowNavigationMask().matches(loadingUrl.getHost()))) {
if (isLocalFile(loadingUrl) || loadingUrl.getHost().equalsIgnoreCase(bridge.getHost()) || (bridge.getServerUrl() == null && !bridge.getAppAllowNavigationMask().matches(loadingUrl.getHost()))) {
Logger.debug("Handling local request: " + request.getUrl().toString());
return handleLocalRequest(request, handler);
} else {
Expand Down

0 comments on commit 66f2efb

Please sign in to comment.