From 9be5c98c8c449f1b134acd797681aeb6ddee3187 Mon Sep 17 00:00:00 2001 From: Jens Maier Date: Sun, 31 Aug 2014 02:55:43 +0200 Subject: [PATCH] FIX: Markdown parser: empty links and bbcode parsed as link refs --- test/javascripts/lib/markdown-test.js.es6 | 4 ++++ vendor/assets/javascripts/better_markdown.js | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/test/javascripts/lib/markdown-test.js.es6 b/test/javascripts/lib/markdown-test.js.es6 index 067930e7ddc..56639193efc 100644 --- a/test/javascripts/lib/markdown-test.js.es6 +++ b/test/javascripts/lib/markdown-test.js.es6 @@ -119,6 +119,10 @@ test("Links", function() { cooked("[3]: http://eviltrout.com", "", "It doesn't autolink markdown link references"); + cooked("[]: http://eviltrout.com", "

[]: http://eviltrout.com

", "It doesn't accept empty link references"); + + cooked("[b]label[/b]: description", "

label: description

", "It doesn't accept BBCode as link references"); + cooked("http://discourse.org and http://discourse.org/another_url and http://www.imdb.com/name/nm2225369", "

http://discourse.org and " + "http://discourse.org/another_url and " + diff --git a/vendor/assets/javascripts/better_markdown.js b/vendor/assets/javascripts/better_markdown.js index 5c56a8bde17..6d831e5e4d0 100644 --- a/vendor/assets/javascripts/better_markdown.js +++ b/vendor/assets/javascripts/better_markdown.js @@ -1135,7 +1135,7 @@ }, referenceDefn: function referenceDefn( block, next) { - var re = /^\s*\[(.*?)\]:\s*(\S+)(?:\s+(?:(['"])(.*)\3|\((.*?)\)))?\n?/; + var re = /^\s*\[([^\[\]]+)\]:\s*(\S+)(?:\s+(?:(['"])(.*)\3|\((.*?)\)))?\n?/; // interesting matches are [ , ref_id, url, , title, title ] if ( !block.match(re) ) @@ -1295,6 +1295,8 @@ return [ res[0] + 1, text.charAt(0) ].concat(res[2]); } + if ( res[0] == 1 ) { return [ 2, "[]" ]; } // empty link found. + var consumed = 1 + res[ 0 ], children = res[ 1 ], link,