Fix issue #4962, remove trailing whitespace in caption field when set to uploadMediaDetails (#5085)

* add methods to check and remove trailing whitespace

* fix filter to check and remove trailing whitespace

* fix filter to check and remove trailing space first

* add test and fix filter() and removeTrailingWhitespace()

* caption trailing whitespace: change solution to remove trailing whitespaces when set to uploadMediaDetails

* update code documentation

* add more tests include instance tab, carriage return and Japanese whitespace

* Caption field: Stop blocking Japanese Space, convert to English Space when set to uploadMediaDetails

* Change method name from convertJapSpaceToEngSpace to convertIdeographicSpaceToLatinSpace

* Change pattern name from JapSpacePattern to ideographicSpacePattern
This commit is contained in:
Jiaweeeeeen 2022-10-30 17:58:15 +08:00 committed by GitHub
parent 09564c3eca
commit 3488644938
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 87 additions and 4 deletions

View file

@ -247,4 +247,51 @@ class UploadMediaDetailAdapterUnitTest {
verify(adapterView, times(3)).adapter
}
@Test
fun testRemoveTrailingWhitespace() {
// empty space
val test1 = "test "
val expected1 = "test"
Assert.assertTrue(viewHolder.checkTrailingWhitespace(test1));
Assert.assertEquals(expected1, viewHolder.removeTrailingWhitespace(test1))
val test2 = "test test "
val expected2 = "test test"
Assert.assertTrue(viewHolder.checkTrailingWhitespace(test2));
Assert.assertEquals(expected2, viewHolder.removeTrailingWhitespace(test2))
// No whitespace
val test3 = "No trailing space";
val expected3 = "No trailing space";
Assert.assertFalse(viewHolder.checkTrailingWhitespace(test3))
Assert.assertEquals(expected3, viewHolder.removeTrailingWhitespace(test3))
}
@Test
fun testRemoveTrailingInstanceTab() {
val test = "test\t"
val expected = "test"
Assert.assertTrue(viewHolder.checkTrailingWhitespace(test));
Assert.assertEquals(expected, viewHolder.removeTrailingWhitespace(test))
}
@Test
fun testRemoveTrailingCarriageReturn() {
val test = "test\r"
val expected = "test"
Assert.assertTrue(viewHolder.checkTrailingWhitespace(test));
Assert.assertEquals(expected, viewHolder.removeTrailingWhitespace(test))
}
@Test
fun testCaptionJapaneseCharacters() {
val test1 = "テスト テスト"
val expected1 = "テスト テスト"
Assert.assertEquals(expected1, viewHolder.convertIdeographicSpaceToLatinSpace(test1));
val test2 = "テスト \r \t "
val expected2 = "テスト"
Assert.assertTrue(viewHolder.checkTrailingWhitespace(test2));
Assert.assertEquals(expected2, viewHolder.removeTrailingWhitespace(test2))
}
}

View file

@ -33,7 +33,7 @@ class UploadMediaDetailInputFilterTest {
builder.filters = arrayOf(UploadMediaDetailInputFilter())
//All unusual space characters
val tests = intArrayOf(0x00A0, 0x1680, 0x180E, 0x2000, 0x2005, 0x200B, 0x2028, 0x2029, 0x202F, 0x205F, 0x3000)
val tests = intArrayOf(0x00A0, 0x1680, 0x180E, 0x2000, 0x2005, 0x200B, 0x2028, 0x2029, 0x202F, 0x205F)
for (test: Int in tests) {
builder.insert(0, String(Character.toChars(test)))
Assert.assertEquals(builder.toString(), "")