From 8d6f3f8a379c8d552d2101cf35ae8f6fe956da53 Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 28 Mar 2022 23:40:45 +0200 Subject: [PATCH] Fix code blocks processing --- app/lib/advanced_text_formatter.rb | 2 +- spec/lib/advanced_text_formatter_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/lib/advanced_text_formatter.rb b/app/lib/advanced_text_formatter.rb index 5ce87d3067..728400819c 100644 --- a/app/lib/advanced_text_formatter.rb +++ b/app/lib/advanced_text_formatter.rb @@ -9,7 +9,7 @@ class AdvancedTextFormatter < TextFormatter def block_code(code, _language) <<~HTML.squish -
#{h(code).gsub("\n", '
')}
+
#{ERB::Util.h(code).gsub("\n", '
')}
HTML end diff --git a/spec/lib/advanced_text_formatter_spec.rb b/spec/lib/advanced_text_formatter_spec.rb index c097b86e19..4e859c93c3 100644 --- a/spec/lib/advanced_text_formatter_spec.rb +++ b/spec/lib/advanced_text_formatter_spec.rb @@ -34,6 +34,14 @@ RSpec.describe AdvancedTextFormatter do end end + context 'given a block code' do + let(:text) { "test\n\n```\nint main(void) {\n return 0;\n}\n```\n" } + + it 'formats code using
 and ' do
+          is_expected.to include '
int main'
+        end
+      end
+
       context 'given some quote' do
         let(:text) { "> foo\n\nbar" }