mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2026-01-03 04:30:34 +02:00
Adds test for issue #1340 and changes the regex
This commit is contained in:
parent
7f003eeb62
commit
9e4c4d76e2
2 changed files with 68 additions and 1 deletions
|
|
@ -363,7 +363,7 @@ public class Helper {
|
|||
public static final Pattern mathsComposePattern = Pattern.compile("\\\\\\(.*\\\\\\)|\\\\\\[.*\\\\\\]");
|
||||
public static final Pattern twitterPattern = Pattern.compile("((@[\\w]+)@twitter\\.com)");
|
||||
public static final Pattern youtubePattern = Pattern.compile("(www\\.|m\\.)?(youtube\\.com|youtu\\.be|youtube-nocookie\\.com)/(((?!([\"'<])).)*)");
|
||||
public static final Pattern nitterPattern = Pattern.compile("(mobile\\.|www\\.)?(twitter|x)\\.com([\\w/-]+)");
|
||||
public static final Pattern nitterPattern = Pattern.compile("(?<!\\w)(mobile\\.|www\\.)?(twitter|x)\\.com(/[\\w/-]+)?");
|
||||
public static final Pattern bibliogramPattern = Pattern.compile("(m\\.|www\\.)?instagram.com(/p/[\\w-/]+)");
|
||||
public static final Pattern libredditPattern = Pattern.compile("(www\\.|m\\.)?(reddit\\.com|preview\\.redd\\.it|i\\.redd\\.it|redd\\.it)/(((?!([\"'<])).)*)");
|
||||
public static final Pattern ouichesPattern = Pattern.compile("https?://ouich\\.es/tag/(\\w+)");
|
||||
|
|
|
|||
67
app/src/test/java/app/fedilab/android/HelperUnitTest.java
Normal file
67
app/src/test/java/app/fedilab/android/HelperUnitTest.java
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
package app.fedilab.android;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import app.fedilab.android.mastodon.helper.Helper;
|
||||
|
||||
public class HelperUnitTest {
|
||||
|
||||
@Test
|
||||
public void tests_wwwTwitter_pattern() {
|
||||
String twitterUrl = "https://www.twitter.com/foo";
|
||||
String result = matchTwitter(twitterUrl);
|
||||
assertEquals("https://nitter.net/foo", result);
|
||||
}
|
||||
|
||||
public void tests_Twitter_pattern() {
|
||||
String twitterUrl = "https://twitter.com/foo";
|
||||
String result = matchTwitter(twitterUrl);
|
||||
assertEquals("https://nitter.net/foo", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tests_wwwxcom_pattern() {
|
||||
String twitterUrl = "https://www.x.com/foo";
|
||||
String result = matchTwitter(twitterUrl);
|
||||
assertEquals("https://nitter.net/foo", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tests_xcom_pattern() {
|
||||
String twitterUrl = "https://x.com/foo";
|
||||
String result = matchTwitter(twitterUrl);
|
||||
assertEquals("https://nitter.net/foo", result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void tests_wwwwixdotcom_pattern() {
|
||||
String twitterUrl = "https://www.wix.com/foo";
|
||||
String result = matchTwitter(twitterUrl);
|
||||
assertEquals("https://www.wix.com/foo", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tests_wixdotcom_pattern() {
|
||||
String twitterUrl = "https://wix.com/foo";
|
||||
String result = matchTwitter(twitterUrl);
|
||||
assertEquals("https://wix.com/foo", result);
|
||||
}
|
||||
|
||||
private String matchTwitter(String url){
|
||||
Matcher matcher = Helper.nitterPattern.matcher(url);
|
||||
if (matcher.find()) {
|
||||
final String nitter_directory = matcher.group(3);
|
||||
String nitterHost = "nitter.net";
|
||||
|
||||
|
||||
return "https://" + nitterHost + nitter_directory;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue