Skip to content

Commit 8cfb089

Browse files
authored
Merge pull request #871 from thephpleague/fix-strikethrough-in-autolinks
Fix AutolinkExtension not ignoring trailing strikethrough syntax
2 parents c2ec855 + 06ce7ad commit 8cfb089

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Updates should follow the [Keep a CHANGELOG](https://keepachangelog.com/) princi
66

77
## [Unreleased][unreleased]
88

9+
### Fixed
10+
11+
- Fixed AutolinkExtension not ignoring trailing strikethrough syntax (#867)
12+
913
## [2.2.3] - 2022-02-26
1014

1115
### Fixed

src/Extension/Autolink/UrlAutolinkParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function parse(InlineParserContext $inlineContext): bool
9090
$url = $matches[0];
9191

9292
// Does the URL end with punctuation that should be stripped?
93-
if (\preg_match('/(.+)([?!.,:*_~]+)$/', $url, $matches)) {
93+
if (\preg_match('/(.+?)([?!.,:*_~]+)$/', $url, $matches)) {
9494
// Add the punctuation later
9595
$url = $matches[1];
9696
}

tests/functional/Extension/Autolink/UrlAutolinkParserTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use League\CommonMark\Environment\Environment;
1717
use League\CommonMark\Extension\Autolink\AutolinkExtension;
1818
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
19+
use League\CommonMark\Extension\Strikethrough\StrikethroughExtension;
1920
use League\CommonMark\MarkdownConverter;
2021
use PHPUnit\Framework\TestCase;
2122

@@ -88,4 +89,22 @@ public function dataProviderForAutolinkTests(): iterable
8889
// Issue 492: underscores in URLs (see https://github.com/thephpleague/commonmark/issues/492)
8990
yield ['http://wiki/Puncutation_in_links:_why_its_bad_(and_should_be_avoided)', '<p><a href="http://wiki/Puncutation_in_links:_why_its_bad_(and_should_be_avoided)">http://wiki/Puncutation_in_links:_why_its_bad_(and_should_be_avoided)</a></p>'];
9091
}
92+
93+
public function testUrlAutolinksWithStrikethrough(): void
94+
{
95+
$markdown = '~~Prefix i link: https://aws.amazon.com/emr/features/hadoop/~~';
96+
97+
$environment = new Environment();
98+
$environment->addExtension(new CommonMarkCoreExtension());
99+
$environment->addExtension(new AutolinkExtension());
100+
$environment->addExtension(new StrikethroughExtension());
101+
102+
$converter = new MarkdownConverter($environment);
103+
$html = $converter->convert($markdown)->getContent();
104+
105+
$this->assertSame(
106+
'<p><del>Prefix i link: <a href="https://aws.amazon.com/emr/features/hadoop/">https://aws.amazon.com/emr/features/hadoop/</a></del></p>' . "\n",
107+
$html
108+
);
109+
}
91110
}

0 commit comments

Comments
 (0)