Commit 225ca4b9 authored by Christophe Henry's avatar Christophe Henry

Fix question mark, slashes and other characters being replaced by full-witdh forms

parent 5c8e414b
Pipeline #3596 passed with stage
in 0 seconds
package fr.chenry.android.freshrss.components.subscriptionarticles.webviewutils
import android.content.Intent
import android.content.Intent.*
import android.content.Intent.ACTION_SEND
import android.content.Intent.EXTRA_TEXT
import com.x5.template.Theme
import fr.chenry.android.freshrss.F
import fr.chenry.android.freshrss.R
import fr.chenry.android.freshrss.components.subscriptionarticles.webviewutils.chunkfilters.SentenceCapFilter
import fr.chenry.android.freshrss.components.subscriptionarticles.webviewutils.chunkfilters.StripFragmentFilter
import fr.chenry.android.freshrss.utils.nullIfBlank
object ShareIntent {
private val defaultTemplate = """
......@@ -29,7 +27,5 @@ object ShareIntent {
fun create(attributes: Map<String, String>) = Intent(ACTION_SEND).apply {
type = "text/plain"
putExtra(EXTRA_TEXT, format(attributes))
val feedName = attributes["subscription"]?.nullIfBlank() ?: F.getString(R.string.this_feed)
putExtra(EXTRA_SUBJECT, F.getString(R.string.share_article, feedName))
}
}
......@@ -4,7 +4,7 @@ import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.DeserializationContext
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.databind.deser.std.StringDeserializer
import fr.chenry.android.freshrss.utils.unescapeHtml4
import fr.chenry.android.freshrss.utils.unescape
typealias StreamId = String
......@@ -26,5 +26,5 @@ data class SubscriptionCategoryApiItem(
)
class HtmlEntitiesDeserializer : StringDeserializer() {
override fun deserialize(p: JsonParser?, ctxt: DeserializationContext?) = super.deserialize(p, ctxt).unescapeHtml4()
override fun deserialize(p: JsonParser?, ctxt: DeserializationContext?) = super.deserialize(p, ctxt).unescape()
}
......@@ -22,10 +22,10 @@ class Converters {
fun readStatusToString(liveData: ReadStatus) = liveData.name
@TypeConverter
fun listOfStringToString(list: List<String>) = list.map { it.escapeHtml4() }.joinToString(" ")
fun listOfStringToString(list: List<String>) = list.map { it.escape() }.joinToString(" ")
@TypeConverter
fun stringToListOfString(string: String) = string.split("\\s+".toRegex()).map { it.unescapeHtml4() }
fun stringToListOfString(string: String) = string.split("\\s+".toRegex()).map { it.unescape() }
@TypeConverter
fun bitmapToBlob(bitmap: Bitmap?) =
......
......@@ -6,7 +6,7 @@ import dev.matrix.roomigrant.GenerateRoomMigrations
import fr.chenry.android.freshrss.store.api.models.StreamId
import fr.chenry.android.freshrss.store.database.models.*
import fr.chenry.android.freshrss.utils.Try
import fr.chenry.android.freshrss.utils.escapeHtml4
import fr.chenry.android.freshrss.utils.escape
import kotlinx.coroutines.*
import org.joda.time.LocalDateTime
......@@ -67,9 +67,9 @@ abstract class FreshRSSDabatabase : RoomDatabase() {
fun insertSubscriptionImage(id: String, bitmap: Bitmap) = getSubscriptionsDAO().insertImage(id, bitmap)
fun getSubcriptionsById(id: String) = getSubscriptionsDAO().byId(id)
fun getSubcriptionsBySubscriptionCategory(subscriptionCategory: SubscriptionCategory) =
getSubscriptionsDAO().bySubscriptionCategory("%${subscriptionCategory.id.escapeHtml4()}%")
getSubscriptionsDAO().bySubscriptionCategory("%${subscriptionCategory.id.escape()}%")
fun getSubcriptionsBySubscriptionCategoryAndUnreadCount(subscriptionCategory: SubscriptionCategory) =
getSubscriptionsDAO().bySubscriptionCategoryAndUnreadCount("%${subscriptionCategory.id.escapeHtml4()}%")
getSubscriptionsDAO().bySubscriptionCategoryAndUnreadCount("%${subscriptionCategory.id.escape()}%")
fun getAllSubcriptions() = getSubscriptionsDAO().getAll()
fun getAllUnreadSubcriptions() = getSubscriptionsDAO().getAllUnread()
suspend fun getAllSubcriptionsIds() = getSubscriptionsDAO().getAllIds()
......
......@@ -75,7 +75,7 @@ fun Request.authentify(account: Account) =
fun Request.authorize(account: Account) = this.header("T" to account.writeToken)
fun Any?.unit(): Unit = Unit
fun Any?.unit() = Unit
fun Any.v(message: String) = Log.v(this::class.qualifiedName, message).unit()
fun Any.v(message: Throwable) = Log.v(this::class.qualifiedName, "VERBOSE", message).unit()
fun Any.d(message: String) = Log.d(this::class.qualifiedName, message).unit()
......@@ -91,8 +91,14 @@ fun Any.wtf(message: Throwable) = Log.wtf(this::class.qualifiedName, "WTF", mess
fun String.addTrailingSlash() = if(this.endsWith("/")) this else "$this/"
fun String.removeNewLines() = this.replace("\\s+".toRegex(), " ")
fun String.escapeHtml4() = StringEscapeUtils.escapeHtml4(this).orEmpty()
fun String.unescapeHtml4() = StringEscapeUtils.unescapeHtml4(this).orEmpty()
fun String.escape() = StringEscapeUtils.escapeHtml4(this).orEmpty()
// See https://github.com/FreshRSS/FreshRSS/issues/2770#issuecomment-575208803
fun String?.unescape() = StringEscapeUtils.unescapeHtml4(this).orEmpty().let {s->
var res = s
listOf('’' to '\'', '"' to '"', '^' to '^', '?' to '?', '\' to '\\', '/' to '/', ',' to ',', ';' to ';')
.forEach {res = res.replace(it.first, it.second)}
res
}
fun String?.nullIfBlank() = if(this.isNullOrBlank()) null else this
fun String?.extractURLs(): List<Uri> = if(this.isNullOrBlank()) listOf() else {
this
......
......@@ -35,7 +35,6 @@
<string name="refresh_frequency_30m">30 دقيقة</string>
<string name="title_settings">الإعدادات</string>
<string name="nav_header_subtitle">القائمة</string>
<string name="this_feed">هذا التدفق</string>
<string name="subscription_categories">الفئات</string>
<string name="good_evening_user">عمّ مساؤك %s</string>
<string name="good_morning_user">أسعدت صباحًا %s</string>
......
......@@ -27,7 +27,6 @@
<string name="title_unread">Non lus</string>
<string name="unread">non lu</string>
<string name="title_favorites">Favoris</string>
<string name="this_feed">ce flux</string>
<string name="read">lu</string>
<string name="prompt_login">Identifiant</string>
<string name="error_instance">Cette URL n\'est pas correcte</string>
......
......@@ -94,7 +94,6 @@
<string name="good_evening_user">Good evening%s</string>
<string name="subscription_categories">Categories</string>
<string name="share_article">Share article of %s</string>
<string name="this_feed">this feed</string>
<string name="instance_url_malformed">This URL is malformed</string>
<string name="no_internet_connection_avaible">There is no internet connection avaible for now, please retry later</string>
<!-- Other messages -->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment