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();