From d516c575fdee172192056942fe65fc662a5852d0 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Thu, 1 Dec 2022 10:56:16 +1000 Subject: [PATCH] FIX: Handle null svg class for excerpt parsing (#19276) Follow-up to 9d50790530459535164870bd49e712c30d2d5e8e In certain cases the svg may not a class, so we just need safe navigation to avoid an error here. --- lib/excerpt_parser.rb | 2 +- spec/lib/excerpt_parser_spec.rb | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/excerpt_parser.rb b/lib/excerpt_parser.rb index 7c236d69afd..2a4fbc8e3b1 100644 --- a/lib/excerpt_parser.rb +++ b/lib/excerpt_parser.rb @@ -136,7 +136,7 @@ class ExcerptParser < Nokogiri::XML::SAX::Document when "svg" attributes = Hash[*attributes.flatten] - if attributes["class"].include?("d-icon") && @keep_svg + if attributes["class"]&.include?("d-icon") && @keep_svg include_tag(name, attributes) @in_svg = true end diff --git a/spec/lib/excerpt_parser_spec.rb b/spec/lib/excerpt_parser_spec.rb index a4f5ecb1b93..cdc7adc0c87 100644 --- a/spec/lib/excerpt_parser_spec.rb +++ b/spec/lib/excerpt_parser_spec.rb @@ -42,6 +42,9 @@ RSpec.describe ExcerptParser do html = '' expect(ExcerptParser.get_excerpt(html, 100, { keep_svg: true })).to match_html('') + html = '' + expect(ExcerptParser.get_excerpt(html, 100, { keep_svg: true })).to match_html('') + html = '' expect(ExcerptParser.get_excerpt(html, 100, { keep_svg: true })).to match_html('') end