Skip to content

Commit

Permalink
Bug fix in URL detection
Browse files Browse the repository at this point in the history
  • Loading branch information
thevindu-w committed Dec 5, 2023
1 parent 8d0d135 commit 672e6fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Expand Up @@ -12,8 +12,8 @@ android {
applicationId = "com.tw.clipshare"
minSdkVersion 24
targetSdkVersion 31
versionCode = 20900
versionName = "2.9.0"
versionCode = 20901
versionName = "2.9.1"
resConfigs "en"
}

Expand Down
28 changes: 14 additions & 14 deletions app/src/main/java/com/tw/clipshare/ClipShareActivity.java
Expand Up @@ -39,6 +39,7 @@
import android.os.Bundle;
import android.provider.OpenableColumns;
import android.text.method.ScrollingMovementMethod;
import android.util.Patterns;
import android.view.*;
import android.widget.*;
import androidx.activity.result.ActivityResultLauncher;
Expand Down Expand Up @@ -422,15 +423,8 @@ private Proto getProtoWrapper(
private void openInBrowser() {
try {
try {
String uri;
if (ClipShareActivity.this.receivedURI.startsWith("https://")
|| ClipShareActivity.this.receivedURI.startsWith("http://")
|| ClipShareActivity.this.receivedURI.startsWith("ftp://")) {
uri = ClipShareActivity.this.receivedURI;
} else {
uri = "http://" + ClipShareActivity.this.receivedURI;
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
Intent intent =
new Intent(Intent.ACTION_VIEW, Uri.parse(ClipShareActivity.this.receivedURI));
startActivity(intent);
} catch (Exception ignored) {
}
Expand Down Expand Up @@ -667,6 +661,16 @@ private void sendFromURIs(ArrayList<Uri> uris) {
}
}

private void checkURL(String url) {
if (!url.matches("^[a-z]{1,12}://.*$")) {
url = "http://" + url;
}
if (Patterns.WEB_URL.matcher(url).matches()) {
ClipShareActivity.this.receivedURI = url;
runOnUiThread(() -> openBrowserLayout.setVisibility(View.VISIBLE));
}
}

private void clkGetTxt() {
try {
runOnUiThread(
Expand All @@ -689,11 +693,7 @@ private void clkGetTxt() {
utils.setClipboardText(text);
if (text.length() < 16384) outputAppend("Received: " + text);
else outputAppend("Received: " + text.substring(0, 1024) + " ... (truncated)");
if (text.matches(
"^((http|https|ftp)://)?([0-9a-zA-Z_.-]{1,256}(:[^\\s@:/?#]{1,256})?@)?[0-9a-zA-Z_-]{1,256}(\\.[0-9a-zA-Z_-]{1,256}){0,256}(:(0|[1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))?(/[^\\s/?#]+)*/?(\\?[^\\s?&#]+=[^\\s?&#]*(&[^\\s?&#]+=[^\\s?&#]*)*)?(#\\S*)?$")) {
ClipShareActivity.this.receivedURI = text;
runOnUiThread(() -> openBrowserLayout.setVisibility(View.VISIBLE));
}
checkURL(text);
} catch (Exception e) {
outputAppend("Error " + e.getMessage());
}
Expand Down

0 comments on commit 672e6fd

Please sign in to comment.