From 94fed772ed15cf6aaf4d6dff664dd149030ea72c Mon Sep 17 00:00:00 2001 From: mym0404 Date: Tue, 19 Mar 2024 02:29:22 +0900 Subject: [PATCH] feat: add decodeFull logic for splitted strings --- lib/src/util.dart | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/src/util.dart b/lib/src/util.dart index 6e0b6224..ca93e04f 100644 --- a/lib/src/util.dart +++ b/lib/src/util.dart @@ -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();