Skip to content
This repository was archived by the owner on Apr 4, 2020. It is now read-only.

Commit aa88bb5

Browse files
committed
Fix incorrect double-linking of standard CommonMark autolinks (fixes #12)
1 parent a49a2d1 commit aa88bb5

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased][unreleased]
99

10+
## [0.3.1] - 2019-06-17
11+
12+
### Fixed
13+
14+
- Fixed extension incorrectly double-linking standard CommonMark autolinks (#12)
15+
1016
## [0.3.0] - 2019-04-10
1117

1218
### Changed
@@ -41,7 +47,8 @@ This release brings the email and URL autolink processors into alignment with th
4147

4248
Initial release!
4349

44-
[unreleased]: https://github.com/thephpleague/commonmark-ext-autolink/compare/v0.3.0...HEAD
50+
[unreleased]: https://github.com/thephpleague/commonmark-ext-autolink/compare/v0.3.1...HEAD
51+
[0.3.1]: https://github.com/thephpleague/commonmark-ext-autolink/compare/v0.3.0...v0.3.1
4552
[0.3.0]: https://github.com/thephpleague/commonmark-ext-autolink/compare/v0.2.1...v0.3.0
4653
[0.2.1]: https://github.com/thephpleague/commonmark-ext-autolink/compare/v0.2.0...v0.2.1
4754
[0.2.0]: https://github.com/thephpleague/commonmark-ext-autolink/compare/v0.1.0...v0.2.0

src/EmailAutolinkProcessor.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ public function processDocument(Document $document)
3030
$walker = $document->walker();
3131

3232
while ($event = $walker->next()) {
33-
if ($event->getNode() instanceof Text) {
34-
self::processAutolinks($event->getNode());
33+
$node = $event->getNode();
34+
if ($node instanceof Text && !($node->parent() instanceof Link)) {
35+
self::processAutolinks($node);
3536
}
3637
}
3738
}

src/UrlAutolinkProcessor.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ public function processDocument(Document $document)
5959
$walker = $document->walker();
6060

6161
while ($event = $walker->next()) {
62-
if ($event->getNode() instanceof Text) {
63-
self::processAutolinks($event->getNode(), $this->finalRegex);
62+
$node = $event->getNode();
63+
if ($node instanceof Text && !($node->parent() instanceof Link)) {
64+
self::processAutolinks($node, $this->finalRegex);
6465
}
6566
}
6667
}

tests/EmailAutolinkProcessorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,8 @@ public function dataProviderForEmailAutolinks()
4747
yield ['[email protected].', '<p><a href="mailto:[email protected]">[email protected]</a>.</p>'];
4848
4949
yield ['[email protected]_', '<p>[email protected]_</p>'];
50+
51+
// Regression: CommonMark autolinks should not be double-linked
52+
yield ['<[email protected]>', '<p><a href="mailto:[email protected]">[email protected]</a></p>'];
5053
}
5154
}

tests/UrlAutolinkProcessorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,8 @@ public function dataProviderForAutolinkTests()
7272

7373
// Regression: two links with one underscore each
7474
yield ["https://eventum.example.net/history.php?iss_id=107092\nhttps://gitlab.example.net/group/project/merge_requests/39#note_150630", "<p><a href=\"https://eventum.example.net/history.php?iss_id=107092\">https://eventum.example.net/history.php?iss_id=107092</a>\n<a href=\"https://gitlab.example.net/group/project/merge_requests/39#note_150630\">https://gitlab.example.net/group/project/merge_requests/39#note_150630</a></p>"];
75+
76+
// Regression: CommonMark autolinks should not be double-linked
77+
yield ['<https://www.google.com>', '<p><a href="https://www.google.com">https://www.google.com</a></p>'];
7578
}
7679
}

0 commit comments

Comments
 (0)