Skip to content

Commit

Permalink
Line breaks not saved in descriptions fixed#2394 (#2803)
Browse files Browse the repository at this point in the history
* Fix line breaks

* modified test to check for line break in description

* added a concern method for sanitize description
  • Loading branch information
rachit3006 committed Jan 28, 2022
1 parent 952c510 commit 3da565f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
7 changes: 2 additions & 5 deletions app/controllers/assignments_controller.rb
Expand Up @@ -2,6 +2,7 @@

class AssignmentsController < ApplicationController
include ActionView::Helpers::SanitizeHelper
include SanitizeDescription

before_action :authenticate_user!
before_action :set_assignment, only: %i[show edit update destroy start reopen close]
Expand Down Expand Up @@ -182,10 +183,6 @@ def check_access
end

def sanitize_assignment_description
@assignment.description = sanitize(
@assignment.description,
tags: %w[img p strong em a sup sub del u span h1 h2 h3 h4 hr li ol ul blockquot],
attributes: %w[style src href alt title target]
)
@assignment.description = sanitize_description(@assignment.description)
end
end
13 changes: 13 additions & 0 deletions app/controllers/concerns/sanitize_description.rb
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module SanitizeDescription
extend ActiveSupport::Concern

def sanitize_description(description)
sanitize(
description,
tags: %w[img p strong em a sup sub del u span h1 h2 h3 h4 hr li ol ul blockquote br],
attributes: %w[style src href alt title target]
)
end
end
7 changes: 2 additions & 5 deletions app/controllers/projects_controller.rb
Expand Up @@ -2,6 +2,7 @@

class ProjectsController < ApplicationController
include ActionView::Helpers::SanitizeHelper
include SanitizeDescription

before_action :set_project, only: %i[show edit update destroy create_fork change_stars]
before_action :authenticate_user!, only: %i[edit update destroy create_fork change_stars]
Expand Down Expand Up @@ -139,10 +140,6 @@ def sanitize_name

# Sanitize description before passing to view
def sanitize_project_description
@project.description = sanitize(
@project.description,
tags: %w[img p strong em a sup sub del u span h1 h2 h3 h4 hr li ol ul blockquote],
attributes: %w[style src href alt title target]
)
@project.description = sanitize_description(@project.description)
end
end
6 changes: 3 additions & 3 deletions spec/controllers/assignments_controller_spec.rb
Expand Up @@ -84,17 +84,17 @@
let(:update_params) do
{
assignment: {
description: "updated description"
description: "updated description <br> with line break"
}
}
end

context "mentor is signed in" do
it "updates the assignment" do
it "updates the assignment and description contains line breaks" do
sign_in @mentor
put group_assignment_path(@group, @assignment), params: update_params
@assignment.reload
expect(@assignment.description).to eq("updated description")
expect(@assignment.description).to eq("updated description <br> with line break")
end
end

Expand Down

0 comments on commit 3da565f

Please sign in to comment.