Skip to content

[markdown] Do not double-encode percent-encoded sequences in autolinks - #2480

Open
TsubasaYoshida wants to merge 2 commits into
dart-lang:mainfrom
TsubasaYoshida:markdown-autolink-percent-encoding
Open

[markdown] Do not double-encode percent-encoded sequences in autolinks#2480
TsubasaYoshida wants to merge 2 commits into
dart-lang:mainfrom
TsubasaYoshida:markdown-autolink-percent-encoding

Conversation

@TsubasaYoshida

Copy link
Copy Markdown

Fixes #2479

AutolinkExtensionSyntax built the href with Uri.encodeFull, which escapes % itself, so an already percent-encoded destination like https://example.com/%40foo became https://example.com/%2540foo.

This PR preserves pre-existing %XX sequences and percent-encodes only the rest, matching how normalizeLinkDestination treats inline link destinations (https://spec.commonmark.org/0.30/#example-502). Note it deliberately does not reuse normalizeLinkDestination itself, since that would additionally decode HTML character references and change behavior for destinations containing e.g. &.

  • Added three cases to test/extensions/autolink_extension.unit (pre-encoded sequences preserved, non-ASCII characters still encoded, invalid % still escaped to %25)
  • Added a CHANGELOG entry under the unreleased 7.4.0 section

@google-cla

google-cla Bot commented Jul 29, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request resolves an issue in AutolinkExtensionSyntax where percent-encoded sequences in autolink destinations were being double-encoded. It introduces a helper method _encodeDestination to preserve existing percent-encoded sequences while encoding other characters. Relevant unit tests and a changelog entry have been added. There are no review comments, so I have no feedback to provide.

AutolinkExtensionSyntax built the href with Uri.encodeFull, which
escapes '%' itself, so an already percent-encoded destination like
https://example.com/%40foo became https://example.com/%2540foo.

Preserve pre-existing %XX sequences and only encode the rest, matching
how normalizeLinkDestination treats inline link destinations
(https://spec.commonmark.org/0.30/#example-502).
@TsubasaYoshida
TsubasaYoshida force-pushed the markdown-autolink-percent-encoding branch from 744ec1a to 14a25af Compare July 29, 2026 02:34
Add version bump since 7.4.0 is intended for publish.
@natebosch

Copy link
Copy Markdown
Member

@srawlins - is this a similar bug to the other recent fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[markdown] AutolinkExtensionSyntax double-encodes percent-encoded sequences in the destination

2 participants