From fb837e04af12d50c4f1b939c3187b71d65a4bc5f Mon Sep 17 00:00:00 2001 From: Niklas Fasching Date: Wed, 19 Dec 2018 12:06:48 +0100 Subject: [PATCH] Fix parsing of regular links enclosed in [] --- org/inline.go | 2 +- org/testdata/inline.html | 5 +++++ org/testdata/inline.org | 3 ++- org/testdata/inline.pretty_org | 3 ++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/org/inline.go b/org/inline.go index c040687..d7c26a1 100644 --- a/org/inline.go +++ b/org/inline.go @@ -197,7 +197,7 @@ func (d *Document) parseAutoLink(input string, start int) (int, int, Node) { } func (d *Document) parseRegularLink(input string, start int) (int, Node) { - if len(input[start:]) == 0 || input[start+1] != '[' { + if len(input[start:]) < 2 || input[start+1] != '[' || input[start+2] == '[' { return 0, nil } input = input[start:] diff --git a/org/testdata/inline.html b/org/testdata/inline.html index 80280c7..f964b77 100644 --- a/org/testdata/inline.html +++ b/org/testdata/inline.html @@ -101,6 +101,11 @@ regular link to https (image)
  • +regular link enclosed in [] [https://www.example.com] [example.com] +

    +
  • +
  • +

    auto link, i.e. not inside \[[square brackets]\] https://www.example.com

  • diff --git a/org/testdata/inline.org b/org/testdata/inline.org index 9a11445..0068516 100644 --- a/org/testdata/inline.org +++ b/org/testdata/inline.org @@ -25,4 +25,5 @@ 4. regular link to a file (video) [[my-video.mp4]] 5. regular link to http (image) [[http://placekitten.com/200/200#.png]] 6. regular link to https (image) [[https://placekitten.com/200/200#.png]] - 7. auto link, i.e. not inside =\[[square brackets]\]= https://www.example.com + 7. regular link enclosed in [] [[[https://www.example.com]]] [[[https://www.example.com][example.com]]] + 8. auto link, i.e. not inside =\[[square brackets]\]= https://www.example.com diff --git a/org/testdata/inline.pretty_org b/org/testdata/inline.pretty_org index 9a11445..0068516 100644 --- a/org/testdata/inline.pretty_org +++ b/org/testdata/inline.pretty_org @@ -25,4 +25,5 @@ 4. regular link to a file (video) [[my-video.mp4]] 5. regular link to http (image) [[http://placekitten.com/200/200#.png]] 6. regular link to https (image) [[https://placekitten.com/200/200#.png]] - 7. auto link, i.e. not inside =\[[square brackets]\]= https://www.example.com + 7. regular link enclosed in [] [[[https://www.example.com]]] [[[https://www.example.com][example.com]]] + 8. auto link, i.e. not inside =\[[square brackets]\]= https://www.example.com