From c135c4eb82350185f5f8d6bb28adde0159ea775e Mon Sep 17 00:00:00 2001 From: jokakilla Date: Sun, 10 Mar 2024 23:28:34 +0100 Subject: [PATCH 1/2] Allow opening deeplinks with custom schema Before this change opening URLs with a schema different from http/https wasn't possible because the code always prepended http. With this change http is only prepended when no schema is present. --- .../ui/resultfragments/URLResultFragment.java | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/secuso/privacyfriendlycodescanner/qrscanner/ui/resultfragments/URLResultFragment.java b/app/src/main/java/com/secuso/privacyfriendlycodescanner/qrscanner/ui/resultfragments/URLResultFragment.java index 6c725c2..9b071cb 100644 --- a/app/src/main/java/com/secuso/privacyfriendlycodescanner/qrscanner/ui/resultfragments/URLResultFragment.java +++ b/app/src/main/java/com/secuso/privacyfriendlycodescanner/qrscanner/ui/resultfragments/URLResultFragment.java @@ -95,23 +95,14 @@ public void onProceedPressed(Context context) { if (!checked) { Toast.makeText(context, R.string.conform_url, Toast.LENGTH_LONG).show(); } else { - String caption; - String qrurl3; - final String lowercase_qrurl = qrurl.toLowerCase(); - if (!lowercase_qrurl.startsWith("http://") && !lowercase_qrurl.startsWith("https://")) { - qrurl3 = "http://" + qrurl; - - Intent url = new Intent(Intent.ACTION_VIEW);/// !!!! - url.setData(Uri.parse(qrurl3)); - caption = getResources().getStringArray(R.array.url_array)[0]; - startActivity(Intent.createChooser(url, caption)); - } else { - Intent url = new Intent(Intent.ACTION_VIEW);/// !!!! - url.setData(Uri.parse(qrurl).normalizeScheme()); - caption = getResources().getStringArray(R.array.url_array)[0]; - startActivity(Intent.createChooser(url, caption)); - + String urlForIntentData = qrurl; + if (!qrurl.toLowerCase().contains("://")) { + urlForIntentData = "http://" + qrurl; } + Intent url = new Intent(Intent.ACTION_VIEW);/// !!!! + url.setData(Uri.parse(urlForIntentData).normalizeScheme()); + String caption = getResources().getStringArray(R.array.url_array)[0]; + startActivity(Intent.createChooser(url, caption)); } } From 8355304e9f4a6a4b215d0a317a355837e5b4df41 Mon Sep 17 00:00:00 2001 From: jokakilla Date: Mon, 22 Apr 2024 22:34:54 +0200 Subject: [PATCH 2/2] Check qrurl for valid protocol scheme using regex Use regex to verify the url protocol scheme is according to RFC 3986. Of no valid scheme is available add a default scheme. --- .../qrscanner/ui/resultfragments/URLResultFragment.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/secuso/privacyfriendlycodescanner/qrscanner/ui/resultfragments/URLResultFragment.java b/app/src/main/java/com/secuso/privacyfriendlycodescanner/qrscanner/ui/resultfragments/URLResultFragment.java index 9b071cb..13ef823 100644 --- a/app/src/main/java/com/secuso/privacyfriendlycodescanner/qrscanner/ui/resultfragments/URLResultFragment.java +++ b/app/src/main/java/com/secuso/privacyfriendlycodescanner/qrscanner/ui/resultfragments/URLResultFragment.java @@ -28,6 +28,7 @@ import java.util.regex.Pattern; public class URLResultFragment extends ResultFragment { + private static final String VALID_RFC3986_PROTOCOL_SCHEME = "^[a-zA-Z][a-zA-Z0-9+.-]*:.*$"; URIParsedResult result; @@ -96,7 +97,7 @@ public void onProceedPressed(Context context) { Toast.makeText(context, R.string.conform_url, Toast.LENGTH_LONG).show(); } else { String urlForIntentData = qrurl; - if (!qrurl.toLowerCase().contains("://")) { + if (!qrurl.matches(VALID_RFC3986_PROTOCOL_SCHEME)) { urlForIntentData = "http://" + qrurl; } Intent url = new Intent(Intent.ACTION_VIEW);/// !!!!