-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3876 from OSC/backport-motd-erb
markdown_erb needs to sanitize html too (backport #3675)
- Loading branch information
Showing
5 changed files
with
59 additions
and
17 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
apps/dashboard/app/models/motd_formatter/base_formatter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module MotdFormatter | ||
|
||
class BaseFormatter | ||
include ActionView::Helpers::SanitizeHelper | ||
|
||
def safe_content(content) | ||
if Configuration.motd_render_html? | ||
content.html_safe | ||
else | ||
sanitize(content) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module MotdFormatter | ||
# Utility class for rendering Markdown MOTD files after ERB rendering them. | ||
class MarkdownErb | ||
class MarkdownErb < BaseFormatter | ||
attr_reader :content, :title | ||
|
||
def initialize(motd_file) | ||
motd_file ||= MotdFile.new unless motd_file | ||
@title = motd_file.title | ||
@content = OodAppkit.markdown.render(ERB.new(motd_file.content).result) | ||
content = OodAppkit.markdown.render(ERB.new(motd_file.content).result) | ||
@content = safe_content(content) | ||
end | ||
|
||
def to_partial_path | ||
"dashboard/motd_markdown" | ||
'dashboard/motd_markdown' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Some Markdown file | ||
|
||
<script>var msg = 'this was a <%= 'script' %>';</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters