#ほげほげ6 とか半角数字と非ascii文字が混ざったハッシュタグを投稿する時に警告を出さなくする
This commit is contained in:
parent
ea89672d18
commit
289ed55112
|
@ -38,6 +38,12 @@
|
|||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/sample_apng/SubwayTooter.sample_apng.androidTest.iml" filepath="$PROJECT_DIR$/.idea/modules/sample_apng/SubwayTooter.sample_apng.androidTest.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/sample_apng/SubwayTooter.sample_apng.main.iml" filepath="$PROJECT_DIR$/.idea/modules/sample_apng/SubwayTooter.sample_apng.main.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/sample_apng/SubwayTooter.sample_apng.unitTest.iml" filepath="$PROJECT_DIR$/.idea/modules/sample_apng/SubwayTooter.sample_apng.unitTest.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/anko/mastodon-related.SubwayTooter.anko.androidTest.iml" filepath="$PROJECT_DIR$/.idea/modules/anko/mastodon-related.SubwayTooter.anko.androidTest.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/apng_android/mastodon-related.SubwayTooter.apng_android.androidTest.iml" filepath="$PROJECT_DIR$/.idea/modules/apng_android/mastodon-related.SubwayTooter.apng_android.androidTest.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/app/mastodon-related.SubwayTooter.app.androidTest.iml" filepath="$PROJECT_DIR$/.idea/modules/app/mastodon-related.SubwayTooter.app.androidTest.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/base/mastodon-related.SubwayTooter.base.androidTest.iml" filepath="$PROJECT_DIR$/.idea/modules/base/mastodon-related.SubwayTooter.base.androidTest.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/colorpicker/mastodon-related.SubwayTooter.colorpicker.androidTest.iml" filepath="$PROJECT_DIR$/.idea/modules/colorpicker/mastodon-related.SubwayTooter.colorpicker.androidTest.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/emoji/mastodon-related.SubwayTooter.emoji.androidTest.iml" filepath="$PROJECT_DIR$/.idea/modules/emoji/mastodon-related.SubwayTooter.emoji.androidTest.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -68,8 +68,14 @@ class PostImpl(
|
|||
) {
|
||||
companion object {
|
||||
private val log = LogCategory("PostImpl")
|
||||
private val reAscii = """[\x00-\x7f]""".asciiPattern()
|
||||
private val reNotAscii = """[^\x00-\x7f]""".asciiPattern()
|
||||
|
||||
// ハッシュタグ内部の、半角数字以外のASCII文字にマッチする正規表現
|
||||
// 単体テストで使うのでpublig
|
||||
val reTagAsciiNotNumber = """[\x00-\x2f\x3a-\x7f]""".toRegex()
|
||||
|
||||
// ハッシュタグ内部の、非ASCII文字にマッチする正規表現
|
||||
// 単体テストで使うのでpublig
|
||||
val reTagNonAscii = """[^\x00-\x7f]""".toRegex()
|
||||
|
||||
private var lastPostTapped: Long = 0L
|
||||
|
||||
|
@ -434,9 +440,10 @@ class PostImpl(
|
|||
if (PrefB.bpWarnHashtagAsciiAndNonAscii.value) {
|
||||
TootTag.findHashtags(content, account.isMisskey)
|
||||
?.filter {
|
||||
val hasAscii = reAscii.matcher(it).find()
|
||||
val hasNotAscii = reNotAscii.matcher(it).find()
|
||||
hasAscii && hasNotAscii
|
||||
// タグがASCII文字(半角数字を除く)と非ASCII文字の両方を含むか?
|
||||
val hasAscii = reTagAsciiNotNumber.containsMatchIn(it)
|
||||
val hasNonAscii = reTagNonAscii.containsMatchIn(it)
|
||||
hasAscii && hasNonAscii
|
||||
}?.map { "#$it" }
|
||||
?.notEmpty()
|
||||
?.let { badTags ->
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package jp.juggler.subwaytooter
|
||||
|
||||
import jp.juggler.subwaytooter.util.PostImpl
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class TestPostImplTagAscii {
|
||||
@Test
|
||||
fun testPostImplTagAscii() {
|
||||
val reTagNumber = """[0-9]""".toRegex()
|
||||
for (cp in 0..<0x100) {
|
||||
val str = "" + cp.toChar()
|
||||
when {
|
||||
cp >= 0x80 -> {
|
||||
assertTrue(PostImpl.reTagNonAscii.containsMatchIn(str))
|
||||
assertFalse(PostImpl.reTagAsciiNotNumber.containsMatchIn(str))
|
||||
assertFalse(reTagNumber.containsMatchIn(str))
|
||||
}
|
||||
|
||||
cp in '0'.code..'9'.code -> {
|
||||
assertFalse(PostImpl.reTagNonAscii.containsMatchIn(str))
|
||||
assertFalse(PostImpl.reTagAsciiNotNumber.containsMatchIn(str))
|
||||
assertTrue(reTagNumber.containsMatchIn(str))
|
||||
}
|
||||
|
||||
else -> {
|
||||
assertFalse(PostImpl.reTagNonAscii.containsMatchIn(str))
|
||||
assertTrue(PostImpl.reTagAsciiNotNumber.containsMatchIn(str))
|
||||
assertFalse(reTagNumber.containsMatchIn(str))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue