diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/tags/TagsDialog.kt b/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/tags/TagsDialog.kt index 1617446a0655..d51146f237c4 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/tags/TagsDialog.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/tags/TagsDialog.kt @@ -31,7 +31,6 @@ import com.ichi2.anki.R import com.ichi2.anki.analytics.AnalyticsDialogFragment import com.ichi2.anki.model.CardStateFilter import com.ichi2.anki.snackbar.showSnackbar -import com.ichi2.anki.utils.ext.convertToString import com.ichi2.annotations.NeedsTest import com.ichi2.utils.DisplayUtils.resizeWhenSoftInputShown import com.ichi2.utils.TagsUtil @@ -415,13 +414,13 @@ class TagsFile(path: String) : File(path), Parcelable { // https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/formats.md val string = Json.encodeToString(data) Timber.d("persisting tags to disk, length: %d", string.length) - outputStream.writeBytes(string) + outputStream.writeUTF(string) } } fun getData() = DataInputStream(FileInputStream(this)).use { inputStream -> // PERF!!: This takes ~2 seconds with AnKing - Json.decodeFromString(inputStream.convertToString()) + Json.decodeFromString(inputStream.readUTF()) } override fun describeContents(): Int = 0 diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/dialogs/tags/TagsDialogTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/dialogs/tags/TagsDialogTest.kt index 9fb19f816699..e60f14a0f1ef 100644 --- a/AnkiDroid/src/test/java/com/ichi2/anki/dialogs/tags/TagsDialogTest.kt +++ b/AnkiDroid/src/test/java/com/ichi2/anki/dialogs/tags/TagsDialogTest.kt @@ -44,6 +44,7 @@ import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mockito import org.mockito.kotlin.whenever +import timber.log.Timber import java.util.concurrent.atomic.AtomicReference @RunWith(AndroidJUnit4::class) @@ -636,6 +637,21 @@ class TagsDialogTest : RobolectricTest() { } } + @Test + fun `unicode tags can be serialized 16576`() { + val type = TagsDialog.DialogType.FILTER_BY_TAG + val allTags = listOf("02动作状态") + + val args = TagsDialog(ParametersUtils.whatever()) + .withTestArguments(type, emptyList(), allTags) + .arguments + val mockListener = Mockito.mock(TagsDialogListener::class.java) + val factory = TagsDialogFactory(mockListener) + val scenario = FragmentScenario.launch(TagsDialog::class.java, args, R.style.Theme_Light, factory) + scenario.moveToState(Lifecycle.State.STARTED) + scenario.onFragment { Timber.d("Dialog successfully opened") } + } + // these are called 'withTestArguments' due to "extension is shadowed by a member" warnings // this is needed so we can pass in 'targetContext' for context.cacheDir private fun TagsDialog.withTestArguments(