Skip to content

Commit 7cc6cc7

Browse files
committed
store encoded URL separately for URL parsing
1 parent 423bb28 commit 7cc6cc7

4 files changed

Lines changed: 10 additions & 3 deletions

File tree

app/src/main/java/org/wikipedia/notifications/NotificationActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ class NotificationActivity : BaseActivity() {
484484
val n = container.notification!!
485485
markReadItems(listOf(container), markUnread = false, fromUndoOrClick = true, position = itemPosition)
486486
n.contents?.links?.getPrimary()?.let { link ->
487-
val url = link.url
487+
val url = link.encodedUrl
488488
if (url.isNotEmpty()) {
489489
linkHandler.wikiSite = WikiSite(url)
490490
linkHandler.onUrlClick(url, null, "")

app/src/main/java/org/wikipedia/notifications/NotificationPresenter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ object NotificationPresenter {
149149
}
150150

151151
private fun addActionForDiffLink(context: Context, builder: NotificationCompat.Builder, link: Notification.Link, n: Notification) {
152-
val uri = Uri.parse(link.url)
152+
val uri = Uri.parse(link.encodedUrl)
153153
val title = uri.getQueryParameter("title")
154154
val oldRev = uri.getQueryParameter("prev").orEmpty().toLongOrNull() ?: -1
155155
val newRev = uri.getQueryParameter("diff").orEmpty().toLongOrNull() ?: -1

app/src/main/java/org/wikipedia/notifications/db/Notification.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,19 @@ class Notification(var id: Long = 0,
8484
private val description: String = ""
8585
var url: String = ""
8686
private set
87+
var encodedUrl: String = ""
88+
private set
8789
val label: String = ""
8890
val tooltip: String = ""
8991
// The icon could be a string or `false`.
9092
private val icon: JsonElement? = null
9193

9294
init {
95+
encodedUrl = url
96+
if (encodedUrl.startsWith("//")) {
97+
encodedUrl = WikiSite.DEFAULT_SCHEME + "://" + encodedUrl.substring(2)
98+
}
99+
url = UriUtil.decodeURL(url)
93100
if (url.startsWith("//")) {
94101
url = url.replaceFirst("//", WikiSite.DEFAULT_SCHEME + "://")
95102
}

app/src/main/java/org/wikipedia/views/NotificationActionsOverflowView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class NotificationActionsOverflowView(context: Context) : FrameLayout(context) {
114114

115115
private var actionClickListener = OnClickListener {
116116
val link = it.tag as Notification.Link
117-
val url = link.url
117+
val url = link.encodedUrl
118118
val notification = container.notification
119119
if (url.isNotEmpty() && notification != null) {
120120
linkHandler.wikiSite = WikiSite(url)

0 commit comments

Comments
 (0)