From da52ac88b0bbe2f21360861321990b1f0033ee07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 24 Jun 2013 21:38:00 +0200 Subject: [PATCH 1/3] do not throw exception when parsing a bad URI --- lib/cooked_post_processor.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index 1d4b2836cec..fd3fab9acd9 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -181,6 +181,7 @@ class CookedPostProcessor def is_valid_image_uri?(url) uri = URI.parse(url) %w(http https).include? uri.scheme + rescue URI::InvalidURIError end def dirty? From 3d2ef18bb7442d6a493f4cfd5e85ef936d5a9588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 24 Jun 2013 22:25:08 +0200 Subject: [PATCH 2/3] move BBCode formating before the markdown conversion --- .../javascripts/discourse/components/markdown.js | 5 +++-- test/javascripts/components/markdown_test.js | 16 +++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/discourse/components/markdown.js b/app/assets/javascripts/discourse/components/markdown.js index 8f67853f53f..51ade57eb6e 100644 --- a/app/assets/javascripts/discourse/components/markdown.js +++ b/app/assets/javascripts/discourse/components/markdown.js @@ -109,7 +109,8 @@ Discourse.Markdown = { // Extract quotes so their contents are not passed through markdown. converter.hooks.chain("preConversion", function(text) { - var extracted = Discourse.BBCode.extractQuotes(text); + var formated = Discourse.BBCode.format(text, opts); + var extracted = Discourse.BBCode.extractQuotes(formated); quoteTemplate = extracted.template; return extracted.text; }); @@ -184,7 +185,7 @@ Discourse.Markdown = { text = quoteTemplate(text); } - return Discourse.BBCode.format(text, opts); + return text; }); if (opts.sanitize) { diff --git a/test/javascripts/components/markdown_test.js b/test/javascripts/components/markdown_test.js index 83d94cb6c7e..2903f95d2be 100644 --- a/test/javascripts/components/markdown_test.js +++ b/test/javascripts/components/markdown_test.js @@ -68,14 +68,14 @@ test("Links", function() { test("Quotes", function() { cookedOptions("1[quote=\"bob, post:1\"]my quote[/quote]2", { topicId: 2, lookupAvatar: function(name) { return "" + name; } }, - "

1

\n


\n2

", + "

1


\n

2

", "handles quotes properly"); cookedOptions("1[quote=\"bob, post:1\"]my quote[/quote]2", { topicId: 2, lookupAvatar: function(name) { } }, - "

1

\n


\n2

", + "

1


\n

2

", "includes no avatar if none is found"); }); @@ -118,4 +118,10 @@ test("SanitizeHTML", function() { equal(sanitizeHtml("
"), "
"); equal(sanitizeHtml("

hello

"), "

hello

"); -}); \ No newline at end of file +}); + +test("with BBCode", function() { + cooked("[img]http://eviltrout.com/eviltrout.png[/img]", + "

", + "BBCode is parsed first"); +}); From 52b8e6014b4d8de2ea43f780014e4bc894939c1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 24 Jun 2013 22:56:03 +0200 Subject: [PATCH 3/3] forgot to commit the test --- spec/components/cooked_post_processor_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb index efd9d18a14d..7f9d3ea9f42 100644 --- a/spec/components/cooked_post_processor_spec.rb +++ b/spec/components/cooked_post_processor_spec.rb @@ -190,6 +190,10 @@ describe CookedPostProcessor do cpp.is_valid_image_uri?("/tmp/image.png").should == false end + it "doesn't throw exception with a bad URI" do + cpp.is_valid_image_uri?("http://do