mirror of
https://github.com/f-droid/fdroidclient.git
synced 2026-05-24 08:25:00 -04:00
Don't add line breaks behind paragraphs and lists
within the app details description
This commit is contained in:
@@ -212,10 +212,11 @@ private fun AppVersion?.getAntiFeatures(
|
||||
|
||||
@VisibleForTesting
|
||||
internal fun getHtmlDescription(description: String?): String? {
|
||||
return description?.replace("(\\s)(https://\\S+[^\\s.])([\\s\\n.])".toRegex()) {
|
||||
val prefix = it.groups[1]?.value ?: it.value
|
||||
val url = it.groups[2]?.value ?: it.value
|
||||
val suffix = it.groups[3]?.value ?: it.value
|
||||
"$prefix<a href=\"$url\">$url</a>$suffix"
|
||||
}?.replace("\n", "<br>\n")
|
||||
return description?.replace("</?h[1-6]>".toRegex(), "")
|
||||
?.replace("(\\s)(https://\\S+[^\\s.])([\\s\\n.])".toRegex()) {
|
||||
val prefix = it.groups[1]?.value ?: it.value
|
||||
val url = it.groups[2]?.value ?: it.value
|
||||
val suffix = it.groups[3]?.value ?: it.value
|
||||
"$prefix<a href=\"$url\">$url</a>$suffix"
|
||||
}?.replace("(?<!</p>|ul>|</li>)\n".toRegex(), "<br>\n")
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ import org.fdroid.ui.details.getHtmlDescription
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
/**
|
||||
* Tests modifications to app details descriptions done in [getHtmlDescription].
|
||||
*/
|
||||
class HtmlDescriptionTest {
|
||||
@Test
|
||||
fun testLinks() {
|
||||
@@ -28,4 +31,22 @@ class HtmlDescriptionTest {
|
||||
val expectedDescription = """please visit our website: <a href="https://wikimediafoundation.org/">https://wikimediafoundation.org/</a>."""
|
||||
assertEquals(expectedDescription, getHtmlDescription(description))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testHeadlineRemoval() {
|
||||
val description = """<h1>SimpleX - the first messaging platform that has no user identifiers, not even random numbers!</h1>
|
||||
<p><a href="https://simplex.chat/blog/20221108-simplex-chat-v4.2-security-audit-new-website.html" target="_blank">Security assessment</a> was done by Trail of Bits in November 2022.</p>
|
||||
<p>SimpleX Chat features:</p>
|
||||
<ul>
|
||||
<li>end-to-end encrypted messages, with editing, replies and deletion of messages.</li>
|
||||
<li>sending end-to-end encrypted images and files.</li>"""
|
||||
|
||||
val expectedDescription = """SimpleX - the first messaging platform that has no user identifiers, not even random numbers!<br>
|
||||
<p><a href="https://simplex.chat/blog/20221108-simplex-chat-v4.2-security-audit-new-website.html" target="_blank">Security assessment</a> was done by Trail of Bits in November 2022.</p>
|
||||
<p>SimpleX Chat features:</p>
|
||||
<ul>
|
||||
<li>end-to-end encrypted messages, with editing, replies and deletion of messages.</li>
|
||||
<li>sending end-to-end encrypted images and files.</li>"""
|
||||
assertEquals(expectedDescription, getHtmlDescription(description))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user