From ad782e450efc2609f169f5d39122c233ed351994 Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Wed, 11 Jan 2023 17:41:02 +0530 Subject: [PATCH] fix: Stop processing broken liquid tags (#6236) --- app/models/concerns/liquidable.rb | 2 ++ spec/models/concerns/liquidable_shared.rb | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/app/models/concerns/liquidable.rb b/app/models/concerns/liquidable.rb index 0ef1594d1..e3d6cb64d 100644 --- a/app/models/concerns/liquidable.rb +++ b/app/models/concerns/liquidable.rb @@ -26,6 +26,8 @@ module Liquidable template = Liquid::Template.parse(modified_liquid_content) self.content = template.render(message_drops) + rescue Liquid::Error + # If there is an error in the liquid syntax, we don't want to process it end def modified_liquid_content diff --git a/spec/models/concerns/liquidable_shared.rb b/spec/models/concerns/liquidable_shared.rb index 530b76a59..e488e6e4e 100644 --- a/spec/models/concerns/liquidable_shared.rb +++ b/spec/models/concerns/liquidable_shared.rb @@ -36,6 +36,12 @@ shared_examples_for 'liqudable' do expect(message.content).to eq 'Can we send you an email at ?' end + it 'will skip processing broken liquid tags' do + message.content = 'Can we send you an email at {{contact.email} {{hi}} ?' + message.save! + expect(message.content).to eq 'Can we send you an email at {{contact.email} {{hi}} ?' + end + it 'will not process liquid tags in multiple code blocks' do message.content = 'hey {{contact.name}} how are you? ```code: {{contact.name}}``` ``` code: {{contact.name}} ``` test `{{contact.name}}`' message.save!