Skip to content

fix: allow non-ASCII letters everywhere in a GFM autolink host (IJPL-91081) - #229

Closed
jetbrains-air[bot] wants to merge 2 commits into
masterfrom
gfm-autolink-unicode-host
Closed

jetbrains-air[bot] wants to merge 2 commits into
masterfrom
gfm-autolink-unicode-host

Conversation

@jetbrains-air

@jetbrains-air jetbrains-air Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Fixes the remaining library-side defect behind IJPL-91081 "Markdown: Link does not render properly".

Investigation

The repro reported in the issue and its comments — an inline link followed immediately by letters, e.g. Check [here](https://www.jetbrains.com/)asdf or [여기](https://www.jetbrains.com/)에서 확인하세요. — no longer reproduces at HEAD: it was fixed back in 0.2.1 by the autolink pushback logic (pushbackAutolink() in _GFMLexer). Verified for all samples from the issue, its screenshots, and the linked gist, with both the batch and the streaming parser.

What is still broken at HEAD is the same user scenario with a bare GFM autolink. HOST_PART was defined as

{ALPHANUM}([a-zA-Z0-9_-]*{ALPHANUM})?

i.e. a Unicode letter was accepted only as the first or last character of a host segment, while the interior was ASCII-only. Consequences:

  • https://www.jetbrains.com에서 확인 lexed as autolink https://www.jetbrains.com에 + text 서 확인 — exactly one Korean letter absorbed into the host, the following word split in the middle, and a click leads to a wrong URL (the reported symptom).
  • Unicode (IDN) domains were cut short: https://例え.テスト/ linked only https://例え.

Fix

Make the whole host segment Unicode-aware:

HOST_PART={ALPHANUM}(({ALPHANUM}|[_-])*{ALPHANUM})?

This matches the GFM reference implementation: cmark-gfm's check_domain/is_valid_hostchar accepts any non-space, non-punctuation character in a domain, so github.com links https://www.jetbrains.com에서 as one unit and never splits a word after the domain. ASCII behavior is unchanged (full CommonMark + GFM spec suites pass).

The checked-in _GFMLexer.kt was regenerated with JFlex 1.9.2 (IntelliJ fork) and idea-flex.skeleton. The toolchain was validated by first regenerating from the unmodified gfm.flex and confirming all packed DFA tables matched the checked-in file exactly; the fix then only changes the four DFA tables (686 → 683 states) — character maps and action code are untouched.

Note: sfm.flex has the same HOST_PART pattern, but was deliberately left unchanged — SFM autolinks are TLD-based and changing their Unicode handling is a separate, riskier decision.

Verification

  • New regression tests in GfmTest cover the issue's inline-link repro (English + Korean) and the bare-autolink cases (Korean word after domain, Unicode domain).
  • jvmTest: 1553 tests pass, 0 failures (includes CommonMark and GFM spec suites and file-based HTML tests).
  • jsNodeTest: passes.

Produced by Air Automations. Name: Markdown library: fix the bug / Run: https://air.jetbrains.cloud/org/05cf1a7f-6ab5-713b-abd3-29d0c8a05e2d/automations/cb6a17f6-e7a9-41a8-9611-7c95c4eb0141?run=78ebdf41-2c32-4f98-a7d7-10425f900ab9

🤖 Generated with Claude Code

…91081)

HOST_PART accepted a Unicode letter only as the first or last character
of a host segment, so `https://www.jetbrains.com에서` was lexed as an
autolink ending after a single Korean letter (`…com에`), splitting the
following word in the middle, and Unicode domains were cut short.
Now the whole segment is Unicode-aware, matching cmark-gfm, which
accepts any non-space non-punctuation character in a domain.

Produced by Air Automations. Name: Markdown library: fix the bug / Run: https://air.jetbrains.cloud/org/05cf1a7f-6ab5-713b-abd3-29d0c8a05e2d/automations/cb6a17f6-e7a9-41a8-9611-7c95c4eb0141?run=78ebdf41-2c32-4f98-a7d7-10425f900ab9

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@donnerpeter

Copy link
Copy Markdown
Member

Merged manually

@donnerpeter
Peter Gromov (donnerpeter) deleted the gfm-autolink-unicode-host branch September 25, 2026 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant