Skip to content

Commit

Permalink
Remove auto-fill with http for not-schema url
Browse files Browse the repository at this point in the history
  • Loading branch information
yjfnypeu committed Oct 31, 2018
1 parent 3fcb5cd commit bacd9d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
8 changes: 5 additions & 3 deletions router-api/src/main/java/com/lzh/nonview/router/Router.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public final class Router{
private InternalCallback internalCallback;

private Router(Uri uri) {
this.uri = Utils.completeUri(uri);
this.uri = uri;
internalCallback = new InternalCallback(this.uri);
}

Expand All @@ -72,7 +72,7 @@ private Router(Uri uri) {
* @return new Router
*/
public static Router create(String url) {
return new Router(Uri.parse(url));
return new Router(Uri.parse(url == null?"":url));
}

/**
Expand Down Expand Up @@ -182,7 +182,9 @@ public IRoute getRoute () {

private IRoute getLocalRoute() {
RouteRule rule;
if ((rule = ActionRoute.findRule(uri, Cache.TYPE_ACTION_ROUTE)) != null) {
if (!Utils.isValidUri(uri)) {
return new IRoute.EmptyRoute(internalCallback);
} else if ((rule = ActionRoute.findRule(uri, Cache.TYPE_ACTION_ROUTE)) != null) {
return new ActionRoute().create(uri, rule, new Bundle(), internalCallback);
} else if ((rule = ActivityRoute.findRule(uri, Cache.TYPE_ACTIVITY_ROUTE)) != null) {
return new ActivityRoute().create(uri, rule, new Bundle(), internalCallback);
Expand Down
19 changes: 4 additions & 15 deletions router-api/src/main/java/com/lzh/nonview/router/tools/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,6 @@ public static String format(String url) {
return url;
}

/**
* <p>
* Check and completed the uri when it was build without a 'scheme'.
* in this case. the default scheme '<b>http</b>' will be added.
* </p>
* @param uri source uri
* @return complete uri
*/
public static Uri completeUri(Uri uri) {
if (TextUtils.isEmpty(uri.getScheme())) {
return Uri.parse("http://" + uri.toString());
}
return uri;
}

public static void checkInterceptor(Uri uri, RouteBundleExtras extras, Context context, List<RouteInterceptor> interceptors) {
for (RouteInterceptor interceptor : interceptors) {
if (interceptor.intercept(uri,extras,context)) {
Expand All @@ -90,4 +75,8 @@ public static boolean isValid(Activity activity) {
&& !activity.isFinishing()
&& !(Build.VERSION.SDK_INT >= 17 && activity.isDestroyed());
}

public static boolean isValidUri(Uri uri) {
return uri != null && !TextUtils.isEmpty(uri.getScheme()) && !TextUtils.isEmpty(uri.getHost());
}
}

0 comments on commit bacd9d2

Please sign in to comment.