fix: obay explicitly set ports in mxc URLs

This commit is contained in:
Sorunome 2021-10-21 11:10:06 +02:00
parent 63397701b5
commit 5c87b560b9
No known key found for this signature in database
GPG Key ID: B19471D07FC9BE9C
2 changed files with 16 additions and 3 deletions

View File

@ -24,8 +24,8 @@ extension MxcUriExtension on Uri {
/// Returns a download Link to this content.
Uri getDownloadLink(Client matrix) => isScheme('mxc')
? matrix.homeserver != null
? matrix.homeserver
?.resolve('_matrix/media/r0/download/$host$path') ??
? matrix.homeserver?.resolve(
'_matrix/media/r0/download/$host${hasPort ? ':$port' : ''}$path') ??
Uri()
: Uri()
: this;
@ -48,7 +48,7 @@ extension MxcUriExtension on Uri {
return Uri(
scheme: homeserver.scheme,
host: homeserver.host,
path: '/_matrix/media/r0/thumbnail/$host$path',
path: '/_matrix/media/r0/thumbnail/$host${hasPort ? ':$port' : ''}$path',
port: homeserver.port,
queryParameters: {
if (width != null) 'width': width.round().toString(),

View File

@ -73,5 +73,18 @@ void main() {
.toString(),
'https://fakeserver.notexisting:1337/_matrix/media/r0/thumbnail/exampleserver.abc/abcdefghijklmn?width=50&height=50&method=scale&animated=true');
});
test('other remote port', () async {
final client = Client('testclient', httpClient: FakeMatrixApi());
await client.checkHomeserver('https://fakeserver.notexisting',
checkWellKnown: false);
final mxc = 'mxc://exampleserver.abc:1234/abcdefghijklmn';
final content = Uri.parse(mxc);
expect(content.isScheme('mxc'), true);
expect(content.getDownloadLink(client).toString(),
'${client.homeserver.toString()}/_matrix/media/r0/download/exampleserver.abc:1234/abcdefghijklmn');
expect(content.getThumbnail(client, width: 50, height: 50).toString(),
'${client.homeserver.toString()}/_matrix/media/r0/thumbnail/exampleserver.abc:1234/abcdefghijklmn?width=50&height=50&method=crop&animated=false');
});
});
}