Skip to content

Commit

Permalink
feat: add decodeFull logic for splitted strings
Browse files Browse the repository at this point in the history
  • Loading branch information
mym0404 committed Mar 18, 2024
1 parent bdf01c0 commit 94fed77
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/src/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,19 @@ String normalizeLinkDestination(String destination) {

final regex = RegExp('%[0-9A-Fa-f]{2}');
final matches = regex.allMatches(destination).toList();
final substrings = destination
.split(regex)
.map((e) => Uri.encodeFull(decodeHtmlCharacters(e)))
.toList();

final buffer = StringBuffer(substrings[0]);
final splitIterator = destination.split(regex).map((e) {
try {
e = Uri.decodeFull(e);
} catch (_) {}
return Uri.encodeFull(decodeHtmlCharacters(e));
}).iterator;

splitIterator.moveNext();
final buffer = StringBuffer(splitIterator.current);
for (var i = 0; i < matches.length; i++) {
splitIterator.moveNext();
buffer.write(matches[i].match);
buffer.write(substrings[i + 1]);
buffer.write(splitIterator.current);
}

return buffer.toString();
Expand Down

0 comments on commit 94fed77

Please sign in to comment.