Skip to content

Commit

Permalink
Fix white-space display in Journal diff (#16810)
Browse files Browse the repository at this point in the history
* Add test for newlines

* Fix html_safe_gsub
  • Loading branch information
oliverguenther authored Sep 25, 2024
1 parent 6a0253d commit 1cf8097
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@ def html_hours(text)

def html_safe_gsub(string, *gsub_args, &)
html_safe = string.html_safe?
string.gsub(*gsub_args, &)
result = string.gsub(*gsub_args, &)

# We only mark the string as safe if the previous string was already safe
if html_safe
string.html_safe # rubocop:disable Rails/OutputSafety
result.html_safe # rubocop:disable Rails/OutputSafety
else
string
result
end
end

Expand Down
8 changes: 6 additions & 2 deletions spec/controllers/journals_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
let(:params) { { id: work_package.last_journal.id.to_s, field: :description, format: "js" } }

before do
work_package.update_attribute :description, "description"
work_package.update_attribute :description, "description\nmore changes"
end

describe "with a user having :view_work_package permission" do
Expand All @@ -62,7 +62,11 @@
expect(response.body.strip).to be_html_eql <<-HTML
<div class="text-diff">
<label class="hidden-for-sighted">Begin of the insertion</label>
<ins class="diffmod">description</ins>
<ins class="diffmod">
description
<br/>
more changes
</ins>
<label class="hidden-for-sighted">End of the insertion</label>
</div>
HTML
Expand Down

0 comments on commit 1cf8097

Please sign in to comment.