Skip to content

Commit

Permalink
fix x pattern match
Browse files Browse the repository at this point in the history
closes #5
  • Loading branch information
AucT committed Aug 17, 2023
1 parent d25614d commit 1268d1e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "eu.auct.twitter2nitter"
minSdk 21
targetSdk 33
versionCode 6
versionName "1.5"
versionCode 8
versionName "1.7"
resourceConfigurations += ["en"]

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/eu/auct/twitter2nitter/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class MainActivity : AppCompatActivity() {
}

private fun getTweet(input: String): String? {
val pattern: Pattern = Pattern.compile(".*?(twitter|x)\\.com(/.*?)(\\s|\$|&)")
val pattern: Pattern = Pattern.compile(".*?(twitter|[/.]x)\\.com(/.*?)(\\s|\$|&)")
val matcher: Matcher = pattern.matcher(input)
matcher.find()

Expand Down
12 changes: 10 additions & 2 deletions app/src/test/java/eu/auct/twitter2nitter/ExampleUnitTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ class ExampleUnitTest {


private fun getTweet(input: String): String? {
val pattern: Pattern = Pattern.compile(".*?(twitter|x)\\.com(/.*?)(\\s|\$|&)")
val pattern: Pattern = Pattern.compile(".*?(twitter|[/.]x)\\.com(/.*?)(\\s|\$|&)")
val matcher: Matcher = pattern.matcher(input)
matcher.find()
return matcher.group(2)
try {
return matcher.group(2)
} catch (t: Throwable) {
return null
}
}
@Test

Expand All @@ -40,6 +44,10 @@ class ExampleUnitTest {
assertEquals( "/AucT", getTweet("http://x.com/AucT"))
assertEquals( "/AucT", getTweet("http://www.x.com/AucT"))

assertEquals( null, getTweet("http://mywebx.com/AucT"))
assertEquals( null, getTweet("https://mywebx.com/AucT"))
assertEquals( null, getTweet("http://www.mywebx.com/AucT"))
assertEquals( null, getTweet("https://www.mywebx.com/AucT"))
}

}

0 comments on commit 1268d1e

Please sign in to comment.