diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/SplashFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/SplashFragment.java index d1326c58..3296d3c6 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/SplashFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/SplashFragment.java @@ -260,9 +260,9 @@ public class SplashFragment extends AppKitFragment{ private void loadAndChooseDefaultServer(){ ClipData clipData=getActivity().getSystemService(ClipboardManager.class).getPrimaryClip(); if(clipData!=null && clipData.getItemCount()>0){ - CharSequence clipText=clipData.getItemAt(0).coerceToText(getActivity()); - if(HtmlParser.INVITE_LINK_PATTERN.matcher(clipText).find()){ - currentInviteLink=Uri.parse(clipText.toString()); + String clipText=clipData.getItemAt(0).coerceToText(getActivity()).toString(); + if(HtmlParser.isValidInviteUrl(clipText)){ + currentInviteLink=Uri.parse(clipText); defaultServerButton.setText(getString(R.string.join_server_x_with_invite, currentInviteLink.getHost())); } }else{ diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/InstanceCatalogSignupFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/InstanceCatalogSignupFragment.java index 68decec3..56afdd3c 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/InstanceCatalogSignupFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/InstanceCatalogSignupFragment.java @@ -370,7 +370,7 @@ public class InstanceCatalogSignupFragment extends InstanceCatalogFragment imple protected void proceedWithAuthOrSignup(Instance instance){ if(currentInviteLinkAlert!=null){ currentInviteLinkAlert.dismiss(); - }else if(!TextUtils.isEmpty(currentSearchQuery) && HtmlParser.INVITE_LINK_PATTERN.matcher(currentSearchQueryButWithCasePreserved).find()){ + }else if(!TextUtils.isEmpty(currentSearchQuery) && HtmlParser.isValidInviteUrl(currentSearchQueryButWithCasePreserved)){ if(TextUtils.isEmpty(inviteCode) || !Objects.equals(instance.uri, inviteCodeHost)){ Uri inviteLink=Uri.parse(currentSearchQueryButWithCasePreserved); new CheckInviteLink(inviteLink.getPath()) @@ -543,8 +543,8 @@ public class InstanceCatalogSignupFragment extends InstanceCatalogFragment imple ClipData clipData=getActivity().getSystemService(ClipboardManager.class).getPrimaryClip(); if(clipData!=null && clipData.getItemCount()>0){ - CharSequence clipText=clipData.getItemAt(0).coerceToText(getActivity()); - if(HtmlParser.INVITE_LINK_PATTERN.matcher(clipText).find()){ + String clipText=clipData.getItemAt(0).coerceToText(getActivity()).toString(); + if(HtmlParser.isValidInviteUrl(clipText)){ edit.setText(clipText); supportingText.setText(R.string.invite_link_pasted); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/text/HtmlParser.java b/mastodon/src/main/java/org/joinmastodon/android/ui/text/HtmlParser.java index e733ab7e..e09d1b4e 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/text/HtmlParser.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/text/HtmlParser.java @@ -52,7 +52,7 @@ public class HtmlParser{ ")" + ")"; public static final Pattern URL_PATTERN=Pattern.compile(VALID_URL_PATTERN_STRING, Pattern.CASE_INSENSITIVE); - public static final Pattern INVITE_LINK_PATTERN=Pattern.compile("^https://"+Regex.URL_VALID_DOMAIN+"/invite/[a-z\\d]+$", Pattern.CASE_INSENSITIVE); + private static final Pattern INVITE_LINK_PATH=Pattern.compile("/invite/[a-z\\d]+$", Pattern.CASE_INSENSITIVE); private static Pattern EMOJI_CODE_PATTERN=Pattern.compile(":([\\w]+):"); private HtmlParser(){} @@ -259,4 +259,8 @@ public class HtmlParser{ } } } + + public static boolean isValidInviteUrl(String url){ + return url.startsWith("https://") && INVITE_LINK_PATH.matcher(url).find(); + } }