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

Commit

Permalink
Fix incorrect double-linking of standard CommonMark autolinks (fixes #12
Browse files Browse the repository at this point in the history
)
  • Loading branch information
colinodell committed Jun 17, 2019
1 parent a49a2d1 commit aa88bb5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased][unreleased]

## [0.3.1] - 2019-06-17

### Fixed

- Fixed extension incorrectly double-linking standard CommonMark autolinks (#12)

## [0.3.0] - 2019-04-10

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

Initial release!

[unreleased]: https://github.com/thephpleague/commonmark-ext-autolink/compare/v0.3.0...HEAD
[unreleased]: https://github.com/thephpleague/commonmark-ext-autolink/compare/v0.3.1...HEAD
[0.3.1]: https://github.com/thephpleague/commonmark-ext-autolink/compare/v0.3.0...v0.3.1
[0.3.0]: https://github.com/thephpleague/commonmark-ext-autolink/compare/v0.2.1...v0.3.0
[0.2.1]: https://github.com/thephpleague/commonmark-ext-autolink/compare/v0.2.0...v0.2.1
[0.2.0]: https://github.com/thephpleague/commonmark-ext-autolink/compare/v0.1.0...v0.2.0
Expand Down
5 changes: 3 additions & 2 deletions src/EmailAutolinkProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ public function processDocument(Document $document)
$walker = $document->walker();

while ($event = $walker->next()) {
if ($event->getNode() instanceof Text) {
self::processAutolinks($event->getNode());
$node = $event->getNode();
if ($node instanceof Text && !($node->parent() instanceof Link)) {
self::processAutolinks($node);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/UrlAutolinkProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ public function processDocument(Document $document)
$walker = $document->walker();

while ($event = $walker->next()) {
if ($event->getNode() instanceof Text) {
self::processAutolinks($event->getNode(), $this->finalRegex);
$node = $event->getNode();
if ($node instanceof Text && !($node->parent() instanceof Link)) {
self::processAutolinks($node, $this->finalRegex);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/EmailAutolinkProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@ public function dataProviderForEmailAutolinks()
yield ['[email protected].', '<p><a href="mailto:[email protected]">[email protected]</a>.</p>'];
yield ['[email protected]', '<p>[email protected]</p>'];
yield ['[email protected]_', '<p>[email protected]_</p>'];

// Regression: CommonMark autolinks should not be double-linked
yield ['<[email protected]>', '<p><a href="mailto:[email protected]">[email protected]</a></p>'];
}
}
3 changes: 3 additions & 0 deletions tests/UrlAutolinkProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,8 @@ public function dataProviderForAutolinkTests()

// Regression: two links with one underscore each
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>"];

// Regression: CommonMark autolinks should not be double-linked
yield ['<https://www.google.com>', '<p><a href="https://www.google.com">https://www.google.com</a></p>'];
}
}

0 comments on commit aa88bb5

Please sign in to comment.