From dea823b6eccd945fad973b57a3e6295160d4f78a Mon Sep 17 00:00:00 2001 From: cyrillefr Date: Mon, 2 Mar 2020 18:50:36 +0100 Subject: [PATCH] Excludes some files from linting and deletes redundancies (#6275) --- .erb-lint.yml | 9 +++++++++ app/helpers/application_helper.rb | 2 +- app/labor/markdown_parser.rb | 8 ++++---- app/models/display_ad.rb | 3 +-- app/views/articles/feed.rss.builder | 2 +- app/views/comments/index.html.erb | 2 +- app/views/internal/comments/index.html.erb | 2 +- app/views/podcast_episodes/show.html.erb | 4 ++-- 8 files changed, 20 insertions(+), 12 deletions(-) diff --git a/.erb-lint.yml b/.erb-lint.yml index 853cd838a..e6a3588a0 100644 --- a/.erb-lint.yml +++ b/.erb-lint.yml @@ -30,4 +30,13 @@ linters: Rails/OutputSafety: Enabled: false Exclude: + - '**/app/views/articles/_block.html.erb' + - '**/app/views/feedback_messages/index.html.erb' - '**/app/views/layouts/_styles.html.erb' + - '**/app/views/liquid_embeds/show.html.erb' + - '**/app/views/moderations/mod.html.erb' + - '**/app/views/pages/live.html.erb' + - '**/app/views/pages/onboarding.html.erb' + - '**/app/views/partnerships/show.html.erb' + - '**/app/views/partnerships/index.html.erb' + - '**/app/views/pro_memberships/show.html.erb' diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 95c900c8a..212e903d8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -99,7 +99,7 @@ module ApplicationHelper end def sanitize_rendered_markdown(processed_html) - ActionController::Base.helpers.sanitize processed_html.html_safe, + ActionController::Base.helpers.sanitize processed_html, scrubber: RenderedMarkdownScrubber.new end diff --git a/app/labor/markdown_parser.rb b/app/labor/markdown_parser.rb index 8f7f00912..c35c6d476 100644 --- a/app/labor/markdown_parser.rb +++ b/app/labor/markdown_parser.rb @@ -46,7 +46,7 @@ class MarkdownParser allowed_tags = %w[strong abbr aside em p h1 h2 h3 h4 h5 h6 i u b code pre br ul ol li small sup sub img a span hr blockquote kbd] allowed_attributes = %w[href strong em ref rel src title alt class] - ActionController::Base.helpers.sanitize markdown.render(@content).html_safe, + ActionController::Base.helpers.sanitize markdown.render(@content), tags: allowed_tags, attributes: allowed_attributes end @@ -58,7 +58,7 @@ class MarkdownParser markdown = Redcarpet::Markdown.new(renderer, REDCARPET_CONFIG) allowed_tags = %w[strong i u b em p br code] allowed_attributes = %w[href strong em ref rel src title alt class] - ActionController::Base.helpers.sanitize markdown.render(@content).html_safe, + ActionController::Base.helpers.sanitize markdown.render(@content), tags: allowed_tags, attributes: allowed_attributes end @@ -70,7 +70,7 @@ class MarkdownParser markdown = Redcarpet::Markdown.new(renderer, REDCARPET_CONFIG) allowed_tags = %w[strong i u b em code] allowed_attributes = %w[href strong em ref rel src title alt class] - ActionController::Base.helpers.sanitize markdown.render(@content).html_safe, + ActionController::Base.helpers.sanitize markdown.render(@content), tags: allowed_tags, attributes: allowed_attributes end @@ -83,7 +83,7 @@ class MarkdownParser allowed_tags = %w[strong abbr aside em p h4 h5 h6 i u b code pre br ul ol li small sup sub a span hr blockquote kbd] allowed_attributes = %w[href strong em ref rel src title alt class] - ActionController::Base.helpers.sanitize markdown.render(@content).html_safe, + ActionController::Base.helpers.sanitize markdown.render(@content), tags: allowed_tags, attributes: allowed_attributes end diff --git a/app/models/display_ad.rb b/app/models/display_ad.rb index 983b7bc95..6ab1fe294 100644 --- a/app/models/display_ad.rb +++ b/app/models/display_ad.rb @@ -26,11 +26,10 @@ class DisplayAd < ApplicationRecord renderer = Redcarpet::Render::HTMLRouge.new(hard_wrap: true, filter_html: false) markdown = Redcarpet::Markdown.new(renderer) initial_html = markdown.render(body_markdown) - # Temporarily disable the sanitisation in order to launch the SheCoded Campaign. # TODO: [@thepracticaldev/cool] find an alternate solution. - # stripped_html = ActionController::Base.helpers.sanitize initial_html.html_safe, + # stripped_html = ActionController::Base.helpers.sanitize initial_html, # tags: %w[a em i b u br img h1 h2 h3 h4 div style], # attributes: %w[href target src height width style] stripped_html = initial_html.html_safe diff --git a/app/views/articles/feed.rss.builder b/app/views/articles/feed.rss.builder index 08d12b19c..6f478fd0c 100644 --- a/app/views/articles/feed.rss.builder +++ b/app/views/articles/feed.rss.builder @@ -16,7 +16,7 @@ xml.rss version: "2.0" do xml.pubDate article.published_at.to_s(:rfc822) if article.published_at xml.link "https://dev.to#{article.path}" xml.guid "https://dev.to#{article.path}" - xml.description sanitize article.processed_html.html_safe, + xml.description sanitize article.processed_html, tags: %w[strong em a table tbody thead tfoot th tr td col colgroup del p h1 h2 h3 h4 h5 h6 blockquote iframe time div span i em u b ul ol li dd dl dt q code pre img sup cite center br small], attributes: %w[href strong em class ref rel src title alt colspan height width size rowspan span value start data-conversation data-lang id] end diff --git a/app/views/comments/index.html.erb b/app/views/comments/index.html.erb index b8afbe6cc..73af0e039 100644 --- a/app/views/comments/index.html.erb +++ b/app/views/comments/index.html.erb @@ -55,7 +55,7 @@ <% if @commentable.processed_html.present? %> <% if @commentable.processed_html.size < 350 %>
- <%= sanitize_rendered_markdown(@commentable.processed_html.html_safe) %> + <%= sanitize_rendered_markdown(@commentable.processed_html) %>
<% else %>
diff --git a/app/views/internal/comments/index.html.erb b/app/views/internal/comments/index.html.erb index c36c73d11..c9684d351 100644 --- a/app/views/internal/comments/index.html.erb +++ b/app/views/internal/comments/index.html.erb @@ -11,7 +11,7 @@

- <%= sanitize comment.processed_html.html_safe, + <%= sanitize comment.processed_html, tags: %w[strong em p h1 h2 h3 h4 h5 h6 i u b code pre br ul ol li small sup img a span hr blockquote], attributes: %w[href strong em ref rel src title alt class] %> diff --git a/app/views/podcast_episodes/show.html.erb b/app/views/podcast_episodes/show.html.erb index a687ea82b..24df8f2a7 100644 --- a/app/views/podcast_episodes/show.html.erb +++ b/app/views/podcast_episodes/show.html.erb @@ -90,9 +90,9 @@

<% if @episode.podcast.feed_url.include?("soundcloud") %> - <%= simple_format((@episode.processed_html || @episode.body).html_safe, sanitize: true) %> + <%= simple_format((@episode.processed_html || @episode.body), sanitize: true) %> <% else %> - <%= sanitize (@episode.processed_html || "").html_safe, + <%= sanitize (@episode.processed_html || ""), tags: %w[strong br em a table tbody thead tfoot th tr td col colgroup del p h1 h2 h3 h4 h5 h6 blockquote time div span i em u b ul ol li dd dl dt q code pre img sup cite center small], attributes: %w[href strong em class ref rel src title alt colspan height width size rowspan span value start data-conversation data-lang id] %> <% end %>