diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java | 55 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/utils/Patterns.java | 2 |
2 files changed, 38 insertions, 19 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java index 0c2238cdb..5d38094bf 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java @@ -15,6 +15,7 @@ import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.AsyncTask; +import android.os.Build; import android.preference.PreferenceManager; import android.support.annotation.ColorInt; import android.support.v4.app.ActivityCompat; @@ -116,7 +117,43 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie } }; - private static final Linkify.MatchFilter WEBURL_MATCH_FILTER = (cs, start, end) -> start < 1 || (cs.charAt(start - 1) != '@' && cs.charAt(start - 1) != '.' && !cs.subSequence(Math.max(0, start - 3), start).equals("://")); + private static String removeTrailingBracket(final String url) { + int numOpenBrackets = 0; + for (char c : url.toCharArray()) { + if (c == '(') { + ++numOpenBrackets; + } else if (c == ')') { + --numOpenBrackets; + } + } + if (numOpenBrackets != 0 && url.charAt(url.length() - 1) == ')') { + return url.substring(0, url.length() - 1); + } else { + return url; + } + } + + private static final Linkify.MatchFilter WEBURL_MATCH_FILTER = (cs, start, end) -> { + if (start > 0) { + if (cs.charAt(start - 1) == '@' || cs.charAt(start - 1) == '.' + || cs.subSequence(Math.max(0, start - 3), start).equals("://")) { + return false; + } + } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + if (end < cs.length()) { + // Reject strings that were probably matched only because they contain a dot followed by + // by some known TLD (see also comment for WORD_BOUNDARY in Patterns.java) + if (Character.isAlphabetic(cs.charAt(end - 1)) && Character.isAlphabetic(cs.charAt(end))) { + return false; + } + } + } + + return true; + }; + private static final Linkify.MatchFilter XMPPURI_MATCH_FILTER = (s, start, end) -> { XmppUri uri = new XmppUri(s.subSequence(start, end).toString()); return uri.isJidValid(); @@ -140,22 +177,6 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie updatePreferences(); } - private static String removeTrailingBracket(final String url) { - int numOpenBrackets = 0; - for (char c : url.toCharArray()) { - if (c == '(') { - ++numOpenBrackets; - } else if (c == ')') { - --numOpenBrackets; - } - } - if (numOpenBrackets != 0 && url.charAt(url.length() - 1) == ')') { - return url.substring(0, url.length() - 1); - } else { - return url; - } - } - public static boolean cancelPotentialWork(Message message, ImageView imageView) { final BitmapWorkerTask bitmapWorkerTask = getBitmapWorkerTask(imageView); diff --git a/src/main/java/de/pixart/messenger/utils/Patterns.java b/src/main/java/de/pixart/messenger/utils/Patterns.java index 38f5641b0..ad6493db2 100644 --- a/src/main/java/de/pixart/messenger/utils/Patterns.java +++ b/src/main/java/de/pixart/messenger/utils/Patterns.java @@ -384,7 +384,6 @@ public class Patterns { + "(?:" + PORT_NUMBER + ")?" + ")" + "(?:" + PATH_AND_QUERY + ")?" - + WORD_BOUNDARY + ")"; /** * Regular expression to match strings that start with a supported protocol. Rules for domain @@ -398,7 +397,6 @@ public class Patterns { + "(?:" + PORT_NUMBER + ")?" + ")" + "(?:" + PATH_AND_QUERY + ")?" - + WORD_BOUNDARY + ")"; /** * Regular expression pattern to match IRIs. If a string starts with http(s):// the expression |