Guess URL scheme

This commit is contained in:
M66B 2021-08-10 16:27:16 +02:00
parent 7c5ffd3508
commit 28b826a22c
2 changed files with 16 additions and 3 deletions

View File

@ -573,8 +573,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if (link.length > 0) {
String url = link[0].getURL();
Uri uri = Uri.parse(url);
if (uri.getScheme() == null)
uri = Uri.parse("https://" + url);
int start = buffer.getSpanStart(link[0]);
int end = buffer.getSpanEnd(link[0]);

View File

@ -44,6 +44,7 @@ import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.webkit.URLUtil;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
@ -119,7 +120,7 @@ public class FragmentDialogOpenLink extends FragmentDialogBase {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
final Uri uri = getArguments().getParcelable("uri");
Uri _uri = getArguments().getParcelable("uri");
String _title = getArguments().getString("title");
if (_title != null)
_title = _title.replace("\uFFFC", ""); // Object replacement character
@ -135,6 +136,20 @@ public class FragmentDialogOpenLink extends FragmentDialogBase {
// Preload web view
Helper.customTabsWarmup(context);
final Uri uri;
if (_uri.getScheme() == null) {
Uri g = Uri.parse(URLUtil.guessUrl(_uri.toString()));
String scheme = g.getScheme();
if (scheme != null) {
if ("http".equals(scheme))
scheme = "https";
uri = Uri.parse(scheme + "://" + _uri.toString());
}
else
uri = _uri;
} else
uri = _uri;
// Process link
final Uri sanitized;
if (uri.isOpaque())