fix: use autolinks for URLs that contain an ampersand

The link text goes through TextConverter, which escapes `&` to `&`,
while the href is the decoded attribute value, so `$href === $text` never
held for a URL with a query string like `?a=1&b=2`. Undo that escaping
before comparing. Only `&amp;` is undone: `<` and `>` cannot appear in an
autolink, so those links keep the inline form.

Fixes #248
This commit is contained in:
dualfroz committed 2026-10-03 02:27:25 +02:00
1 parent a82cc3b9b6
commit 94062cea69
2 files changed
+3 -1

No files matched your search

+1 -1
View File
@@ -26,7 +26,7 @@ class LinkConverter implements ConverterInterface, ConfigurationAwareInterface
if ($title !== '') {
$markdown = '[' . $text . '](' . $href . ' "' . $title . '")';
} elseif ($href === $text && $this->isValidAutolink($href)) {
} elseif ($href === \str_replace('&amp;', '&', $text) && $this->isValidAutolink($href)) {
$markdown = '<' . $href . '>';
} elseif ($href === 'mailto:' . $text && $this->isValidEmail($text)) {
$markdown = '<' . $text . '>';