Merge pull request #6035 from element-hq/fix/remove-fragment-part-in-mxc-urls

Add `MediaSource.safeUrl` for removing invalid fragment part from URLs
This commit is contained in:
Benoit Marty 2026-03-03 11:57:49 +01:00 committed by GitHub
commit b65b9eeab9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 53 additions and 15 deletions

View file

@ -9,6 +9,7 @@
package io.element.android.libraries.matrix.api.media
import android.os.Parcelable
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize
@Parcelize
@ -16,9 +17,20 @@ data class MediaSource(
/**
* Url of the media.
*/
val url: String,
private val url: String,
/**
* This is used to hold data for encrypted media.
*/
val json: String? = null,
) : Parcelable
) : Parcelable {
/**
* A URL with invalid parts (like `#fragment`, if it's an MXC url) removed.
*/
@IgnoredOnParcel
val safeUrl = if (url.startsWith("mxc")) {
// We've seen some MXC urls in the wild having some `mxc://foo/bar#auto` fragment suffix, which is invalid
url.substringBefore("#")
} else {
url
}
}