Skip to content

🐛 Match linkify schemes as ASCII only - #493

Open
shashank11yadav wants to merge 1 commit into
executablebooks:masterfrom
shashank11yadav:fix/linkify-ascii-scheme
Open

shashank11yadav wants to merge 1 commit into
executablebooks:masterfrom
shashank11yadav:fix/linkify-ascii-scheme

Conversation

@shashank11yadav

Copy link
Copy Markdown

With linkify enabled, a bare URL that comes right after ſ (U+017F, LATIN SMALL LETTER LONG S) or K (U+212A, KELVIN SIGN) is not linkified. The same URL after é or ! is.

SCHEME_RE in markdown_it/rules_inline/linkify.py is compiled with re.IGNORECASE on a str pattern, so Python uses Unicode case folding. [a-z] then also matches these two characters, the captured scheme becomes ſhttp / Khttp, and linkify-it rejects it. Adding re.ASCII limits the scheme to ASCII letters, as the RFC 3986 comment above the regex already says. rules_block/html_block.py uses the same ASCII-only approach for its case-insensitive patterns.

Open PR #485 replaces SCHEME_RE with an ASCII-only backscan, so it would also cover this case. The new test applies to either change.

Fixes #492

How it was tested:

  • New test test_linkify_scheme_is_ascii_only in tests/test_linkify.py, parametrized over U+017F and U+212A. Both cases fail without the fix and pass with it.
  • pytest tests: 1192 passed.
  • ruff check ., ruff format --check . (ruff 0.17.4) and mypy --ignore-missing-imports markdown_it tests (mypy 2.4.1) pass. These are the versions pinned in .pre-commit-config.yaml. pre-commit run --all-files itself was not run, so the pre-commit-hooks checks (whitespace, end-of-file, JSON/YAML) were not run.

With re.IGNORECASE on a str pattern, [a-z] also matches U+017F (long s)
and U+212A (Kelvin sign), so a bare URL right after either character was
read as part of the scheme and left unlinked. Add re.ASCII so the scheme
follows RFC 3986, where ALPHA is ASCII only.
Katty53251

This comment was marked as spam.

@Katty53251

Copy link
Copy Markdown

8v6e7y k~~~~

This branch has not been deployed

No deployments
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.

🐛 linkify: bare URL not linkified after "ſ" or Kelvin sign, because SCHEME_RE uses re.IGNORECASE

2 participants