Skip to content

Commit

Permalink
Merge pull request #1860 from famedly/krille/return-empty-uri-instead…
Browse files Browse the repository at this point in the history
…-of-original-url

fix: Return empty uri instead of original uri if uri is not mxc
  • Loading branch information
krille-chan authored Jun 24, 2024
2 parents 7ade992 + f0ab627 commit a792620
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/src/utils/uri_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions test/mxc_uri_extension_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(), '');
});
});
}

0 comments on commit a792620

Please sign in to comment.