From c9ce3525ae7726d75521bb2415bd38a48cdd759c Mon Sep 17 00:00:00 2001 From: Mamoru TASAKA Date: Tue, 10 Sep 2024 21:34:18 +0900 Subject: [PATCH] Support REXML 3.3.3 invalid XML handling With https://github.com/ruby/rexml/commit/2bca7bd84a5cf13af8f5633dd7d3d519fc990d67 REXML now detects invalid XML with unsupported content before root element and raises REXML::ParseException rather than returning empty root. Support this REXML exception in Prawn::SVG::Document initializer. --- lib/prawn/svg/document.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/prawn/svg/document.rb b/lib/prawn/svg/document.rb index b2696cb..0229bcb 100644 --- a/lib/prawn/svg/document.rb +++ b/lib/prawn/svg/document.rb @@ -17,7 +17,11 @@ class Prawn::SVG::Document :color_mode def initialize(data, bounds, options, font_registry: nil, css_parser: CssParser::Parser.new, attribute_overrides: {}) - @root = REXML::Document.new(data).root + begin + @root = REXML::Document.new(data).root + rescue REXML::ParseException + @root = nil + end if @root.nil? if data.respond_to?(:end_with?) && data.end_with?('.svg')