When the GFM extended autolink syntax parses a bare URL that already contains percent-encoded sequences, the generated href gets double-encoded.
import 'package:markdown/markdown.dart';
void main() {
print(markdownToHtml(
'https://example.com/%40foo',
extensionSet: ExtensionSet.gitHubFlavored,
));
}
Actual:
<p><a href="https://example.com/%2540foo">https://example.com/%40foo</a></p>
Expected (matches inline links and cmark-gfm's autolink output):
<p><a href="https://example.com/%40foo">https://example.com/%40foo</a></p>
The inline link form [text](https://example.com/%40foo) already produces the expected output, because normalizeLinkDestination leaves pre-existing percent-encoding alone per https://spec.commonmark.org/0.30/#example-502.
Cause: AutolinkExtensionSyntax.onMatch builds the href with Uri.encodeFull(destination), which escapes % itself, turning %40 into %2540. As a result, bare URLs whose path or query already contains percent-encoded characters link to a wrong destination.
I have a fix ready and will open a PR shortly.
When the GFM extended autolink syntax parses a bare URL that already contains percent-encoded sequences, the generated
hrefgets double-encoded.Actual:
Expected (matches inline links and cmark-gfm's autolink output):
The inline link form
[text](https://example.com/%40foo)already produces the expected output, becausenormalizeLinkDestinationleaves pre-existing percent-encoding alone per https://spec.commonmark.org/0.30/#example-502.Cause:
AutolinkExtensionSyntax.onMatchbuilds the href withUri.encodeFull(destination), which escapes%itself, turning%40into%2540. As a result, bare URLs whose path or query already contains percent-encoded characters link to a wrong destination.I have a fix ready and will open a PR shortly.