Skip to content

Commit

Permalink
MEET-4577 ANRs in MessageText.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
Yenel committed Nov 11, 2024
1 parent 82dcdf6 commit 273f23a
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,31 @@ internal class GetMessageTextTest {
emptyList<String>(),
" Text with bold format"
),
Arguments.of(
"* Text with bold format *",
emptyList<String>(),
" Text with bold format "
),
Arguments.of(
"*Text with bold format *",
emptyList<String>(),
"Text with bold format "
),
Arguments.of(
"*\nText with bold format*",
emptyList<String>(),
"*\nText with bold format*",
),
Arguments.of(
"*\nText with bold format\n*",
emptyList<String>(),
"*\nText with bold format\n*",
),
Arguments.of(
"*Text with bold format\n*",
emptyList<String>(),
"*Text with bold format\n*",
),
Arguments.of(
"*Text with bold format* new bold*",
emptyList<String>(),
Expand All @@ -72,11 +92,31 @@ internal class GetMessageTextTest {
emptyList<String>(),
" Text with italic format"
),
Arguments.of(
"_ Text with italic format _",
emptyList<String>(),
" Text with italic format "
),
Arguments.of(
"_Text with italic format _",
emptyList<String>(),
"Text with italic format "
),
Arguments.of(
"_\nText with italic format_",
emptyList<String>(),
"_\nText with italic format_"
),
Arguments.of(
"_\nText with italic format\n_",
emptyList<String>(),
"_\nText with italic format\n_",
),
Arguments.of(
"_Text with italic format\n_",
emptyList<String>(),
"_Text with italic format\n_"
),
Arguments.of(
"_Text with italic format_ new italic_",
emptyList<String>(),
Expand All @@ -102,11 +142,31 @@ internal class GetMessageTextTest {
emptyList<String>(),
" Text with strikethrough format"
),
Arguments.of(
"~ Text with strikethrough format ~",
emptyList<String>(),
" Text with strikethrough format "
),
Arguments.of(
"~Text with strikethrough format ~",
emptyList<String>(),
"Text with strikethrough format "
),
Arguments.of(
"~\nText with italic format~",
emptyList<String>(),
"~\nText with italic format~"
),
Arguments.of(
"~\nText with italic format\n~",
emptyList<String>(),
"~\nText with italic format\n~",
),
Arguments.of(
"~Text with italic format\n~",
emptyList<String>(),
"~Text with italic format\n~"
),
Arguments.of(
"~Text with strikethrough format~ new strikethrough~",
emptyList<String>(),
Expand Down Expand Up @@ -137,11 +197,31 @@ internal class GetMessageTextTest {
emptyList<String>(),
" Text with quote format"
),
Arguments.of(
"` Text with quote format `",
emptyList<String>(),
" Text with quote format "
),
Arguments.of(
"` Text with quote format`",
emptyList<String>(),
" Text with quote format"
),
Arguments.of(
"`\nText with italic format`",
emptyList<String>(),
"`\nText with italic format`"
),
Arguments.of(
"`\nText with italic format\n`",
emptyList<String>(),
"`\nText with italic format\n`",
),
Arguments.of(
"`Text with italic format\n`",
emptyList<String>(),
"`Text with italic format\n`"
),
Arguments.of(
"`Text with quote format` new quote`",
emptyList<String>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ private fun String.getFormat(formatList: List<Format>, index: Int, formatType: F
val indexAfterFormat = index + formatTypeList.size + if (isMultiQuote) 2 else 0
val indexBeforeFormat = endIndex - formatTypeList.size

if (this[indexAfterFormat] != '\n' && this[indexBeforeFormat] != '\n') {
if (isMultiQuote || (this[indexAfterFormat] != '\n' && this[indexBeforeFormat] != '\n')) {
Format(
formatStart = index,
formatEnd = endIndex,
Expand All @@ -362,7 +362,7 @@ private fun String.getEndFormatIndex(tag: String, isMultiQuote: Boolean, startIn
val endIndex = indexOf(tag, startIndex + formatCharsSize)
val existsStringInFormat = startIndex != endIndex - 1

while (endIndex != -1 && existsStringInFormat) {
if (endIndex != -1 && existsStringInFormat) {
val breaksSimpleFormat = !isMultiQuote && substring(startIndex, endIndex).contains('\n')

if (!breaksSimpleFormat) {
Expand Down

0 comments on commit 273f23a

Please sign in to comment.