Skip to content

Commit 629da94

Browse files
Copilotcolinodell
andcommitted
Fix AutolinkExtension to anchor regex and add test cases
Co-authored-by: colinodell <[email protected]>
1 parent e770275 commit 629da94

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/Extension/Autolink/UrlAutolinkParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class UrlAutolinkParser implements InlineParserInterface
2323
private const ALLOWED_AFTER = [null, ' ', "\t", "\n", "\x0b", "\x0c", "\x0d", '*', '_', '~', '('];
2424

2525
// RegEx adapted from https://github.com/symfony/symfony/blob/6.3/src/Symfony/Component/Validator/Constraints/UrlValidator.php
26-
private const REGEX = '~
26+
private const REGEX = '~^
2727
(
2828
# Must start with a supported scheme + auth, or "www"
2929
(?:

tests/functional/Extension/Autolink/UrlAutolinkParserTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ public static function dataProviderForAutolinkTests(): iterable
9090

9191
// Issue 492: underscores in URLs (see https://github.com/thephpleague/commonmark/issues/492)
9292
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>'];
93+
94+
// Regression: www. (with space) followed by a valid URL should not incorrectly link
95+
yield ['test text www. test https://commonmark.thephpleague.com/2.7/extensions/autolinks/ more text', '<p>test text www. test <a href="https://commonmark.thephpleague.com/2.7/extensions/autolinks/">https://commonmark.thephpleague.com/2.7/extensions/autolinks/</a> more text</p>'];
96+
yield ['www. example.com', '<p>www. example.com</p>'];
97+
yield ['www. https://example.com', '<p>www. <a href="https://example.com">https://example.com</a></p>'];
9398
}
9499

95100
public function testUrlAutolinksWithStrikethrough(): void

0 commit comments

Comments
 (0)