diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b3775706e..4042152fd 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -51,10 +51,12 @@ module ApplicationHelper def format_text(text, **options) raw DTextRagel.parse(text, **options) + rescue DTextRagel::Error => e + raw "" end def strip_dtext(text) - raw(DTextRagel.parse_strip(text)) + format_text(text, strip: true) end def error_messages_for(instance_name) diff --git a/app/presenters/wiki_page_presenter.rb b/app/presenters/wiki_page_presenter.rb index 2207cb3ae..f70822be3 100644 --- a/app/presenters/wiki_page_presenter.rb +++ b/app/presenters/wiki_page_presenter.rb @@ -9,10 +9,6 @@ class WikiPagePresenter wiki_page.body end - def blurb - DTextRagel.parse_strip(excerpt.to_s) - end - # Produce a formatted page that shows the difference between two versions of a page. def diff(other_version) pattern = Regexp.new('(?:<.+?>)|(?:[0-9_A-Za-z\x80-\xff]+[\x09\x20]?)|(?:[ \t]+)|(?:\r?\n)|(?:.+?)') diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb index ec328ec91..325eba7c9 100644 --- a/app/views/posts/index.html.erb +++ b/app/views/posts/index.html.erb @@ -72,7 +72,7 @@ <%= content_tag :link, nil, rel: "prev", href: prev_page_url %> <% end %> <% if @post_set.has_wiki? %> - + <% else %> <% end %> diff --git a/app/views/wiki_pages/show.html.erb b/app/views/wiki_pages/show.html.erb index c7c278abb..113ba7515 100644 --- a/app/views/wiki_pages/show.html.erb +++ b/app/views/wiki_pages/show.html.erb @@ -44,7 +44,7 @@ <% end %> <% content_for(:html_header) do %> - + <% end %> <%= render "secondary_links" %> diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb new file mode 100644 index 000000000..f9f0214de --- /dev/null +++ b/test/helpers/application_helper_test.rb @@ -0,0 +1,14 @@ +require "test_helper" + +class ApplicationHelperTest < ActionView::TestCase + context "The application helper" do + context "format_text method" do + should "not raise an exception for invalid DText" do + dtext = "* a\n" * 513 + + assert_nothing_raised { format_text(dtext) } + assert_equal("", format_text(dtext)) + end + end + end +end