Skip to content

Commit

Permalink
Merge pull request #778 from dewantawsif/android
Browse files Browse the repository at this point in the history
Fix '?' prefix being unescaped on Android target
  • Loading branch information
Alex009 authored Dec 8, 2024
2 parents 8d1bb1f + 438db81 commit ddbf5ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,16 @@ internal fun String.removeAndroidMirroringFormat(): String {
.replace("""\@""", "@")
}

private val androidLinkingCharacters = setOf('@', '?')

internal fun String.convertXmlStringToAndroidLocalization(): String {
// Android resources should comply with requirements:
// https://developer.android.com/guide/topics/resources/string-resource#escaping_quotes
return StringEscapeUtils
.unescapeXml(this)
.replace("\n", "\\n")
.let { StringEscapeUtils.escapeXml11(it) }
.let {
if (it.getOrNull(0) == '@') {
replaceFirst("@", """\@""")
} else {
it
}
}
.replaceFirstChar { if (it in androidLinkingCharacters) "\\$it" else "$it" }
.replace(""", "\\"")
.replace("'", "\\'")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,18 @@ class XmlStringsToPlatformTest {
}

@Test
fun stringLikeAndroidLinkOnStringAndroidTest() {
fun stringLikeAndroidResourceLinkOnStringAndroidTest() {
assertEquals(
expected = """\@same text""",
actual = """@same text""".convertXmlStringToAndroidLocalization()
)
}

@Test
fun stringLikeAndroidAttributeLinkOnStringAndroidTest() {
assertEquals(
expected = """\?same text""",
actual = """?same text""".convertXmlStringToAndroidLocalization()
)
}
}

0 comments on commit ddbf5ed

Please sign in to comment.