Skip to content

Commit

Permalink
Fix order to escape proposal content (#5367)
Browse files Browse the repository at this point in the history
* Fix order to escape proposal content. Related to #5341

* Revert spec changes
  • Loading branch information
oriolgual committed Sep 27, 2019
1 parent d7e9b2f commit 9072a72
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,21 @@ def collaborative_draft_path
end

def title(links: false, extras: true, html_escape: false)
renderer = Decidim::ContentRenderers::HashtagRenderer.new(collaborative_draft.title)
text = renderer.render(links: links, extras: extras).html_safe
text = collaborative_draft.title
text = decidim_html_escape(text) if html_escape
text

renderer = Decidim::ContentRenderers::HashtagRenderer.new(text)
renderer.render(links: links, extras: extras).html_safe
end

def body(links: false, extras: true, strip_tags: false)
renderer = Decidim::ContentRenderers::HashtagRenderer.new(collaborative_draft.body)
text = collaborative_draft.body
text = strip_tags(text) if strip_tags

renderer = Decidim::ContentRenderers::HashtagRenderer.new(text)
text = renderer.render(links: links, extras: extras).html_safe
if strip_tags
text = strip_tags(text)
text = Anchored::Linker.auto_link(text, target: "_blank", rel: "noopener")
end
text

Anchored::Linker.auto_link(text, target: "_blank", rel: "noopener")
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,21 @@ def display_mention
#
# Returns a String.
def title(links: false, extras: true, html_escape: false)
renderer = Decidim::ContentRenderers::HashtagRenderer.new(proposal.title)
text = renderer.render(links: links, extras: extras).html_safe
text = proposal.title
text = decidim_html_escape(text) if html_escape
text

renderer = Decidim::ContentRenderers::HashtagRenderer.new(text)
renderer.render(links: links, extras: extras).html_safe
end

def body(links: false, extras: true, strip_tags: false)
renderer = Decidim::ContentRenderers::HashtagRenderer.new(proposal.body)
text = proposal.body
text = strip_tags(text) if strip_tags

renderer = Decidim::ContentRenderers::HashtagRenderer.new(text)
text = renderer.render(links: links, extras: extras).html_safe
if strip_tags
text = strip_tags(text)
text = Anchored::Linker.auto_link(text, target: "_blank", rel: "noopener")
end
text

Anchored::Linker.auto_link(text, target: "_blank", rel: "noopener")
end
end
end
Expand Down
7 changes: 2 additions & 5 deletions decidim-proposals/spec/system/collaborative_drafts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

describe "Explore Collaborative Drafts", versioning: true, type: :system do
include ActionView::Helpers::TextHelper
include Decidim::SanitizeHelper

include_context "with a component"

Expand Down Expand Up @@ -83,10 +82,8 @@
end
end

let(:sanitized_title) { decidim_html_escape(collaborative_draft.title) }

it "shows the title" do
expect(page).to have_content(sanitized_title)
expect(page).to have_content(collaborative_draft.title)
end

it "shows the body" do
Expand Down Expand Up @@ -116,7 +113,7 @@
end

it "shows the title" do
expect(page).to have_content(sanitized_title)
expect(page).to have_content(collaborative_draft.title)
end

it "shows the body" do
Expand Down
3 changes: 1 addition & 2 deletions decidim-proposals/spec/system/proposals_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

describe "Proposals", type: :system do
include ActionView::Helpers::TextHelper
include Decidim::SanitizeHelper
include_context "with a component"
let(:manifest_name) { "proposals" }

Expand Down Expand Up @@ -47,7 +46,7 @@

click_link proposal.title

expect(page).to have_content(decidim_html_escape(proposal.title))
expect(page).to have_content(proposal.title)
expect(page).to have_content(strip_tags(proposal.body).strip)
expect(page).to have_author(proposal.creator_author.name)
expect(page).to have_content(proposal.reference)
Expand Down

0 comments on commit 9072a72

Please sign in to comment.