fix: Properly handle url encoding in matrix.to URLs
parent
c4431f1089
commit
e5dad936ce
@ -1,24 +1,33 @@
|
|||||||
|
import '../app_config.dart';
|
||||||
|
|
||||||
extension MatrixIdentifierStringExtension on String {
|
extension MatrixIdentifierStringExtension on String {
|
||||||
/// Separates room identifiers with an event id and possibly a query parameter into its components.
|
/// Separates room identifiers with an event id and possibly a query parameter into its components.
|
||||||
MatrixIdentifierStringExtensionResults parseIdentifierIntoParts() {
|
MatrixIdentifierStringExtensionResults parseIdentifierIntoParts() {
|
||||||
final match = RegExp(r'^([#!][^:]*:[^\/?]*)(?:\/(\$[^?]*))?(?:\?(.*))?$')
|
final isUrl = startsWith(AppConfig.inviteLinkPrefix);
|
||||||
.firstMatch(this);
|
var s = this;
|
||||||
|
if (isUrl) {
|
||||||
|
// as we decode a component we may only call it on the url part *before* the "query" part
|
||||||
|
final parts = replaceFirst(AppConfig.inviteLinkPrefix, '').split('?');
|
||||||
|
s = Uri.decodeComponent(parts.removeAt(0)) + '?' + parts.join('?');
|
||||||
|
}
|
||||||
|
final match = RegExp(r'^([#!@+][^:]*:[^\/?]*)(?:\/(\$[^?]*))?(?:\?(.*))?$')
|
||||||
|
.firstMatch(s);
|
||||||
if (match == null) {
|
if (match == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return MatrixIdentifierStringExtensionResults(
|
return MatrixIdentifierStringExtensionResults(
|
||||||
roomIdOrAlias: match.group(1),
|
primaryIdentifier: match.group(1),
|
||||||
eventId: match.group(2),
|
secondaryIdentifier: match.group(2),
|
||||||
queryString: match.group(3),
|
queryString: match.group(3)?.isNotEmpty ?? false ? match.group(3) : null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MatrixIdentifierStringExtensionResults {
|
class MatrixIdentifierStringExtensionResults {
|
||||||
final String roomIdOrAlias;
|
final String primaryIdentifier;
|
||||||
final String eventId;
|
final String secondaryIdentifier;
|
||||||
final String queryString;
|
final String queryString;
|
||||||
|
|
||||||
MatrixIdentifierStringExtensionResults(
|
MatrixIdentifierStringExtensionResults(
|
||||||
{this.roomIdOrAlias, this.eventId, this.queryString});
|
{this.primaryIdentifier, this.secondaryIdentifier, this.queryString});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue