mirror of
https://ghfast.top/https://github.com/discourse/discourse-translator.git
synced 2026-07-16 11:46:33 +08:00
Raw is in general much smaller than cooked. Cooked tends to have a lot of html when it includes things like pulled oneboxes, mentions, images. The gigantic cooked content also increases the amount of time it takes to translate content. In sending raw, we can cook the translated content after it returns from the API. This also helps with sanitisation.
22 lines
675 B
Ruby
22 lines
675 B
Ruby
# frozen_string_literal: true
|
|
|
|
describe DiscourseTranslator::TranslatedContentNormalizer do
|
|
fab!(:post)
|
|
fab!(:topic)
|
|
|
|
it "normalizes the content" do
|
|
expect(
|
|
DiscourseTranslator::TranslatedContentNormalizer.normalize(
|
|
post,
|
|
"<script>alert('test')</script><p> <h1>Testing</h1> This is a test post</p>",
|
|
),
|
|
).to eq("<p> </p><h1>Testing</h1> This is a test post<p></p>")
|
|
|
|
expect(
|
|
DiscourseTranslator::TranslatedContentNormalizer.normalize(
|
|
topic,
|
|
"<script>alert('test')</script><p> <h1>Testing</h1> This is a test post</p>",
|
|
),
|
|
).to eq("<p> </p><h1>Testing</h1> This is a test post<p></p>")
|
|
end
|
|
end
|