Merge pull request #1860 from famedly/krille/return-empty-uri-instead-of-original-url

fix: Return empty uri instead of original uri if uri is not mxc
This commit is contained in:
Krille-chan 2024-06-24 13:36:43 +02:00 committed by GitHub
commit a7926209da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View File

@ -28,7 +28,7 @@ extension MxcUriExtension on Uri {
'_matrix/media/v3/download/$host${hasPort ? ':$port' : ''}$path') ??
Uri()
: Uri()
: this;
: Uri();
/// Returns a scaled thumbnail link to this content with the given `width` and
/// `height`. `method` can be `ThumbnailMethod.crop` or
@ -40,7 +40,7 @@ extension MxcUriExtension on Uri {
num? height,
ThumbnailMethod? method = ThumbnailMethod.crop,
bool? animated = false}) {
if (!isScheme('mxc')) return this;
if (!isScheme('mxc')) return Uri();
final homeserver = matrix.homeserver;
if (homeserver == null) {
return Uri();

View File

@ -82,5 +82,13 @@ void main() {
expect(content.getThumbnail(client, width: 50, height: 50).toString(),
'${client.homeserver.toString()}/_matrix/media/v3/thumbnail/exampleserver.abc:1234/abcdefghijklmn?width=50&height=50&method=crop&animated=false');
});
test('Wrong scheme returns empty object', () async {
final client = Client('testclient', httpClient: FakeMatrixApi());
await client.checkHomeserver(Uri.parse('https://fakeserver.notexisting'),
checkWellKnown: false);
final mxc = Uri.parse('https://wrong-scheme.com');
expect(mxc.getDownloadLink(client).toString(), '');
expect(mxc.getThumbnail(client).toString(), '');
});
});
}