fix: String.parseIdentifierIntoParts not working with unicode matrix.to links
Some clients do not uri-encode the identifier for matrix.to links, so we must handle if we can't uri-decode them
This commit is contained in:
parent
4af6763765
commit
b849c828e3
|
|
@ -74,10 +74,20 @@ extension MatrixIdExtension on String {
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final parameter =
|
var parameter = parameterStr.substring(0, index);
|
||||||
Uri.decodeQueryComponent(parameterStr.substring(0, index));
|
try {
|
||||||
final value =
|
parameter = Uri.decodeQueryComponent(parameter);
|
||||||
Uri.decodeQueryComponent(parameterStr.substring(index + 1));
|
} catch (_) {
|
||||||
|
// do nothing: the parameter wasn't url-encoded, and we already have the
|
||||||
|
// plaintext version in the `parameter` variable
|
||||||
|
}
|
||||||
|
var value = parameterStr.substring(index + 1);
|
||||||
|
try {
|
||||||
|
value = Uri.decodeQueryComponent(value);
|
||||||
|
} catch (_) {
|
||||||
|
// do nothing: the value wasn't url-encoded, and we already have the
|
||||||
|
// plaintext version in the `value` variable
|
||||||
|
}
|
||||||
if (parameter == 'via') {
|
if (parameter == 'via') {
|
||||||
via.add(value);
|
via.add(value);
|
||||||
}
|
}
|
||||||
|
|
@ -132,7 +142,14 @@ extension MatrixIdExtension on String {
|
||||||
if (toLowerCase().startsWith(matrixToPrefix)) {
|
if (toLowerCase().startsWith(matrixToPrefix)) {
|
||||||
// as we decode a component we may only call it on the url part *before* the "query" part
|
// as we decode a component we may only call it on the url part *before* the "query" part
|
||||||
final parts = substring(matrixToPrefix.length).split('?');
|
final parts = substring(matrixToPrefix.length).split('?');
|
||||||
s = Uri.decodeComponent(parts.removeAt(0)) + '?' + parts.join('?');
|
var ident = parts.removeAt(0);
|
||||||
|
try {
|
||||||
|
ident = Uri.decodeComponent(ident);
|
||||||
|
} catch (_) {
|
||||||
|
// do nothing: the identifier wasn't url-encoded, and we already have the
|
||||||
|
// plaintext version in the `ident` variable
|
||||||
|
}
|
||||||
|
s = ident + '?' + parts.join('?');
|
||||||
}
|
}
|
||||||
final match = RegExp(r'^([#!@+][^:]*:[^\/?]*)(?:\/(\$[^?]*))?(?:\?(.*))?$')
|
final match = RegExp(r'^([#!@+][^:]*:[^\/?]*)(?:\/(\$[^?]*))?(?:\?(.*))?$')
|
||||||
.firstMatch(s);
|
.firstMatch(s);
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,10 @@ void main() {
|
||||||
expect(res.primaryIdentifier, '#alias:beep');
|
expect(res.primaryIdentifier, '#alias:beep');
|
||||||
expect(res.secondaryIdentifier, null);
|
expect(res.secondaryIdentifier, null);
|
||||||
expect(res.queryString, null);
|
expect(res.queryString, null);
|
||||||
|
res = 'https://matrix.to/#/#🦊:beep'.parseIdentifierIntoParts();
|
||||||
|
expect(res.primaryIdentifier, '#🦊:beep');
|
||||||
|
expect(res.secondaryIdentifier, null);
|
||||||
|
expect(res.queryString, null);
|
||||||
res = 'https://matrix.to/#/%23alias%3abeep'.parseIdentifierIntoParts();
|
res = 'https://matrix.to/#/%23alias%3abeep'.parseIdentifierIntoParts();
|
||||||
expect(res.primaryIdentifier, '#alias:beep');
|
expect(res.primaryIdentifier, '#alias:beep');
|
||||||
expect(res.secondaryIdentifier, null);
|
expect(res.secondaryIdentifier, null);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue