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:
commit
a7926209da
|
|
@ -28,7 +28,7 @@ extension MxcUriExtension on Uri {
|
||||||
'_matrix/media/v3/download/$host${hasPort ? ':$port' : ''}$path') ??
|
'_matrix/media/v3/download/$host${hasPort ? ':$port' : ''}$path') ??
|
||||||
Uri()
|
Uri()
|
||||||
: Uri()
|
: Uri()
|
||||||
: this;
|
: Uri();
|
||||||
|
|
||||||
/// Returns a scaled thumbnail link to this content with the given `width` and
|
/// Returns a scaled thumbnail link to this content with the given `width` and
|
||||||
/// `height`. `method` can be `ThumbnailMethod.crop` or
|
/// `height`. `method` can be `ThumbnailMethod.crop` or
|
||||||
|
|
@ -40,7 +40,7 @@ extension MxcUriExtension on Uri {
|
||||||
num? height,
|
num? height,
|
||||||
ThumbnailMethod? method = ThumbnailMethod.crop,
|
ThumbnailMethod? method = ThumbnailMethod.crop,
|
||||||
bool? animated = false}) {
|
bool? animated = false}) {
|
||||||
if (!isScheme('mxc')) return this;
|
if (!isScheme('mxc')) return Uri();
|
||||||
final homeserver = matrix.homeserver;
|
final homeserver = matrix.homeserver;
|
||||||
if (homeserver == null) {
|
if (homeserver == null) {
|
||||||
return Uri();
|
return Uri();
|
||||||
|
|
|
||||||
|
|
@ -82,5 +82,13 @@ void main() {
|
||||||
expect(content.getThumbnail(client, width: 50, height: 50).toString(),
|
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');
|
'${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(), '');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue