[automerger] RESTRICT AUTOMERGE Do not linkify text with RLO/LRO characters. am: 73f398d306 am: 363e47e676 am: efb165f557 am: b2b98a008b
Change-Id: I29c3f97af12987c8a1dd8a69529641d32d2dd172
This commit is contained in:
@@ -26,6 +26,7 @@ import android.text.style.URLSpan;
|
|||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
|
import android.util.Log;
|
||||||
import android.util.Patterns;
|
import android.util.Patterns;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@@ -65,6 +66,9 @@ import libcore.util.EmptyArray;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public class Linkify {
|
public class Linkify {
|
||||||
|
|
||||||
|
private static final String LOG_TAG = "Linkify";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bit field indicating that web URLs should be matched in methods that
|
* Bit field indicating that web URLs should be matched in methods that
|
||||||
* take an options mask
|
* take an options mask
|
||||||
@@ -222,6 +226,11 @@ public class Linkify {
|
|||||||
* @return True if at least one link is found and applied.
|
* @return True if at least one link is found and applied.
|
||||||
*/
|
*/
|
||||||
public static final boolean addLinks(@NonNull Spannable text, @LinkifyMask int mask) {
|
public static final boolean addLinks(@NonNull Spannable text, @LinkifyMask int mask) {
|
||||||
|
if (text != null && containsUnsupportedCharacters(text.toString())) {
|
||||||
|
android.util.EventLog.writeEvent(0x534e4554, "116321860", -1, "");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (mask == 0) {
|
if (mask == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -267,6 +276,29 @@ public class Linkify {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the specified text contains at least one unsupported character for applying
|
||||||
|
* links. Also logs the error.
|
||||||
|
*
|
||||||
|
* @param text the text to apply links to
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static boolean containsUnsupportedCharacters(String text) {
|
||||||
|
if (text.contains("\u202C")) {
|
||||||
|
Log.e(LOG_TAG, "Unsupported character for applying links: u202C");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (text.contains("\u202D")) {
|
||||||
|
Log.e(LOG_TAG, "Unsupported character for applying links: u202D");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (text.contains("\u202E")) {
|
||||||
|
Log.e(LOG_TAG, "Unsupported character for applying links: u202E");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scans the text of the provided TextView and turns all occurrences of
|
* Scans the text of the provided TextView and turns all occurrences of
|
||||||
* the link types indicated in the mask into clickable links. If matches
|
* the link types indicated in the mask into clickable links. If matches
|
||||||
@@ -414,6 +446,10 @@ public class Linkify {
|
|||||||
public static final boolean addLinks(@NonNull Spannable spannable, @NonNull Pattern pattern,
|
public static final boolean addLinks(@NonNull Spannable spannable, @NonNull Pattern pattern,
|
||||||
@Nullable String scheme, @Nullable MatchFilter matchFilter,
|
@Nullable String scheme, @Nullable MatchFilter matchFilter,
|
||||||
@Nullable TransformFilter transformFilter) {
|
@Nullable TransformFilter transformFilter) {
|
||||||
|
if (spannable != null && containsUnsupportedCharacters(spannable.toString())) {
|
||||||
|
android.util.EventLog.writeEvent(0x534e4554, "116321860", -1, "");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return addLinks(spannable, pattern, scheme, null, matchFilter,
|
return addLinks(spannable, pattern, scheme, null, matchFilter,
|
||||||
transformFilter);
|
transformFilter);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user