From 0f55cd5b266249de1dd914058e74a235c3ea02bf Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Sun, 27 Jan 2019 20:53:11 +0000 Subject: [PATCH] Permit empty links --- src/Components/Inlines/Link.php | 4 ++-- tests/commonmark/470-Links.html | 4 +--- tests/commonmark/470-Links.md | 6 +----- tests/commonmark/547-Links.html | 1 + tests/commonmark/547-Links.md | 3 +++ 5 files changed, 8 insertions(+), 10 deletions(-) create mode 100644 tests/commonmark/547-Links.html create mode 100644 tests/commonmark/547-Links.md diff --git a/src/Components/Inlines/Link.php b/src/Components/Inlines/Link.php index af9c27c..9d14d2e 100644 --- a/src/Components/Inlines/Link.php +++ b/src/Components/Inlines/Link.php @@ -61,8 +61,8 @@ final class Link implements Inline $remainder = \substr($remainder, $width); - if (\preg_match('/^[(]\s*+((?:[^ ()]++|[(][^ )]+[)])++)(?:[ ]+("[^"]*+"|\'[^\']*+\'))?\s*+[)]/', $remainder, $matches)) { - $url = $matches[1]; + if (\preg_match('/^[(]\s*+(?:((?:[^ ()]++|[(][^ )]+[)])++)(?:[ ]+("[^"]*+"|\'[^\']*+\'))?\s*+)?[)]/', $remainder, $matches)) { + $url = isset($matches[1]) ? $matches[1] : ''; $title = isset($matches[2]) ? \substr($matches[2], 1, - 1) : null; $width += \strlen($matches[0]); diff --git a/tests/commonmark/470-Links.html b/tests/commonmark/470-Links.html index 4a3cb66..782298a 100644 --- a/tests/commonmark/470-Links.html +++ b/tests/commonmark/470-Links.html @@ -1,3 +1 @@ -

link

-

link

-

link

\ No newline at end of file +

link

\ No newline at end of file diff --git a/tests/commonmark/470-Links.md b/tests/commonmark/470-Links.md index efea20f..b84d6c2 100644 --- a/tests/commonmark/470-Links.md +++ b/tests/commonmark/470-Links.md @@ -1,5 +1 @@ -[link](#fragment) - -[link](http://example.com#fragment) - -[link](http://example.com?foo=3#frag) \ No newline at end of file +[link]() \ No newline at end of file diff --git a/tests/commonmark/547-Links.html b/tests/commonmark/547-Links.html new file mode 100644 index 0000000..4134c8f --- /dev/null +++ b/tests/commonmark/547-Links.html @@ -0,0 +1 @@ +

foo

\ No newline at end of file diff --git a/tests/commonmark/547-Links.md b/tests/commonmark/547-Links.md new file mode 100644 index 0000000..0979681 --- /dev/null +++ b/tests/commonmark/547-Links.md @@ -0,0 +1,3 @@ +[foo]() + +[foo]: /url1 \ No newline at end of file