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(android): load local assets when using wildcard on allowNavigation #3834

Merged
merged 3 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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().contains(bridge.getHost()) || (bridge.getServerUrl() == null && !bridge.getAppAllowNavigationMask().matches(loadingUrl.getHost()))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this incorrectly trigger if loadingUrl.getHost() = "something.app" and bridge.getHost() = "app"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed the contains to equalsIgnoreCase

Logger.debug("Handling local request: " + request.getUrl().toString());
return handleLocalRequest(request, handler);
} else {
Expand Down