File tree Expand file tree Collapse file tree 3 files changed +9
-35
lines changed
app/models/concerns/discourse_translator Expand file tree Collapse file tree 3 files changed +9
-35
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ def set_detected_locale(locale)
2424 # @param text [String] the translated text
2525 def set_translation ( locale , text )
2626 locale = locale . to_s . gsub ( "_" , "-" )
27- text = DiscourseTranslator ::TranslatedContentSanitizer . sanitize ( self . class , text )
27+ text = DiscourseTranslator ::TranslatedContentSanitizer . sanitize ( text )
2828 translations . find_or_initialize_by ( locale : locale ) . update! ( translation : text )
2929 end
3030
Original file line number Diff line number Diff line change 22
33module DiscourseTranslator
44 class TranslatedContentSanitizer
5- def self . sanitize ( model , content )
6- case model . to_s
7- when "Topic"
8- return ERB ::Util . html_escape ( content ) unless SiteSetting . title_fancy_entities?
9- Topic . fancy_title ( content )
10- when "Post"
11- PrettyText . cleanup ( content , { } )
12- else
13- # raise an error if the model is not supported
14- raise ArgumentError . new ( "Model not supported" )
15- end
5+ def self . sanitize ( content )
6+ PrettyText . cleanup ( content , { } )
167 end
178 end
189end
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
33describe DiscourseTranslator ::TranslatedContentSanitizer do
4- describe "Posts" do
5- it "sanitizes the content" do
6- sanitized =
7- DiscourseTranslator ::TranslatedContentSanitizer . sanitize (
8- Post ,
9- "<script>alert('test')</script><p> <h1>Testing</h1> This is a test post</p>" ,
10- )
11-
12- expect ( sanitized ) . to eq ( "<p> </p><h1>Testing</h1> This is a test post<p></p>" )
13- end
14- end
15-
16- describe "Topics" do
17- it "escapes and prettifies" do
18- sanitized =
19- DiscourseTranslator ::TranslatedContentSanitizer . sanitize (
20- Topic ,
21- "<script>alert('test')</script><p> <h1>Testing</h1> This is a test post</p>" ,
22- )
23-
24- expect ( sanitized ) . to eq (
25- "<script>alert(‘test’)</script><p> <h1>Testing</h1> This is a test post</p>" ,
4+ it "sanitizes the content" do
5+ sanitized =
6+ DiscourseTranslator ::TranslatedContentSanitizer . sanitize (
7+ "<script>alert('test')</script><p> <h1>Testing</h1> This is a test post</p>" ,
268 )
27- end
9+
10+ expect ( sanitized ) . to eq ( "<p> </p><h1>Testing</h1> This is a test post<p></p>" )
2811 end
2912end
You can’t perform that action at this time.
0 commit comments