Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Commit 94fed77

Browse files
committed
feat: add decodeFull logic for splitted strings
1 parent bdf01c0 commit 94fed77

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

lib/src/util.dart

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,19 @@ String normalizeLinkDestination(String destination) {
5353

5454
final regex = RegExp('%[0-9A-Fa-f]{2}');
5555
final matches = regex.allMatches(destination).toList();
56-
final substrings = destination
57-
.split(regex)
58-
.map((e) => Uri.encodeFull(decodeHtmlCharacters(e)))
59-
.toList();
60-
61-
final buffer = StringBuffer(substrings[0]);
56+
final splitIterator = destination.split(regex).map((e) {
57+
try {
58+
e = Uri.decodeFull(e);
59+
} catch (_) {}
60+
return Uri.encodeFull(decodeHtmlCharacters(e));
61+
}).iterator;
62+
63+
splitIterator.moveNext();
64+
final buffer = StringBuffer(splitIterator.current);
6265
for (var i = 0; i < matches.length; i++) {
66+
splitIterator.moveNext();
6367
buffer.write(matches[i].match);
64-
buffer.write(substrings[i + 1]);
68+
buffer.write(splitIterator.current);
6569
}
6670

6771
return buffer.toString();

0 commit comments

Comments
 (0)