File tree 1 file changed +17
-0
lines changed
1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change
1
+ import 'package:flutter/foundation.dart' ;
1
2
2
3
import '../api/model/narrow.dart' ;
3
4
import 'narrow.dart' ;
@@ -19,6 +20,22 @@ String _encodeHashComponent(String str) {
19
20
.replaceAllMapped (_encodeHashComponentRegex, (Match m) => _hashReplacements[m[0 ]! ]! );
20
21
}
21
22
23
+ /// Decode a dot-encoded string; return null if malformed.
24
+ // The Zulip webapp uses this encoding in narrow-links:
25
+ // https://github.com/zulip/zulip/blob/1577662a6/static/js/hash_util.js#L18-L25
26
+ @visibleForTesting
27
+ String ? decodeHashComponent (String str) {
28
+ try {
29
+ return Uri .decodeComponent (str.replaceAll ('.' , '%' ));
30
+ } on ArgumentError {
31
+ // as with '%1': Invalid argument(s): Truncated URI
32
+ return null ;
33
+ } on FormatException {
34
+ // as with '%FF': FormatException: Invalid UTF-8 byte (at offset 0)
35
+ return null ;
36
+ }
37
+ }
38
+
22
39
/// A URL to the given [Narrow] , on `store` 's realm.
23
40
///
24
41
/// To include /near/{messageId} in the link, pass a non-null [nearMessageId] .
You can’t perform that action at this time.
0 commit comments