From c015692c186fd895bd7a7cc07a4aa476f6e9f96c Mon Sep 17 00:00:00 2001 From: mym0404 Date: Tue, 19 Mar 2024 02:28:58 +0900 Subject: [PATCH] feat: add decodeFull logic for splitted strings --- .idea/codeStyles/Project.xml | 212 +++++++++++++++++++++++++++ .idea/codeStyles/codeStyleConfig.xml | 5 + .idea/misc.xml | 5 + .idea/vcs.xml | 6 + .idea/workspace.xml | 139 ++++++++++++++++++ lib/src/util.dart | 18 ++- 6 files changed, 378 insertions(+), 7 deletions(-) create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 00000000..6910223b --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,212 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 00000000..a55e7a17 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..6e866721 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 00000000..97133392 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,139 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file 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();