Skip to content

Commit 15c5635

Browse files
committed
Do not escape titles as we need to keep compatibility with manual inline translations
1 parent 04b752a commit 15c5635

File tree

3 files changed

+9
-35
lines changed

3 files changed

+9
-35
lines changed

app/models/concerns/discourse_translator/translatable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

lib/discourse_translator/translated_content_sanitizer.rb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,8 @@
22

33
module 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
189
end
Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,12 @@
11
# frozen_string_literal: true
22

33
describe 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-
"&lt;script&gt;alert(&lsquo;test&rsquo;)&lt;/script&gt;&lt;p&gt; &lt;h1&gt;Testing&lt;/h1&gt; This is a test post&lt;/p&gt;",
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
2912
end

0 commit comments

Comments
 (0)