Skip to content

Commit

Permalink
Drop legacy Ruby and Rails support
Browse files Browse the repository at this point in the history
`ERB::Util.html_escape_once` is available in all supported Rails
versions

Also:
- Opt-in for MFA (security)
- Move development gems to Gemfile

Close jamesmartin#161, close jamesmartin#164
  • Loading branch information
tagliala committed Sep 5, 2024
1 parent 275d2af commit bf39922
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ source 'https://rubygems.org'

# Specify your gem's dependencies in inline_svg.gemspec
gemspec

gem "bundler"
gem "pry"
gem "rake"
gem "rspec"
gem "rubocop"
12 changes: 4 additions & 8 deletions inline_svg.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_development_dependency "bundler", "~> 2.0"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec", "~> 3.2"
spec.add_development_dependency "rspec_junit_formatter", "0.2.2"
spec.add_development_dependency "pry"
spec.add_development_dependency "rubocop"
spec.metadata['rubygems_mfa_required'] = 'true'
spec.required_ruby_version = '>= 3.1'

spec.add_runtime_dependency "activesupport", ">= 3.0"
spec.add_runtime_dependency "nokogiri", ">= 1.6"
spec.add_runtime_dependency "activesupport", ">= 6.1"
spec.add_runtime_dependency "nokogiri", ">= 1.16"
end
11 changes: 1 addition & 10 deletions lib/inline_svg/action_view/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ def inline_svg(filename, transform_params={})

private

def backwards_compatible_html_escape(filename)
# html_escape_once was introduced in newer versions of Rails.
if ERB::Util.respond_to?(:html_escape_once)
ERB::Util.html_escape_once(filename)
else
ERB::Util.html_escape(filename)
end
end

def render_inline_svg(filename, transform_params={})
begin
svg_file = read_svg(filename)
Expand Down Expand Up @@ -60,7 +51,7 @@ def read_svg(filename)

def placeholder(filename)
css_class = InlineSvg.configuration.svg_not_found_css_class
not_found_message = "'#{backwards_compatible_html_escape(filename)}' #{extension_hint(filename)}"
not_found_message = "'#{ERB::Util.html_escape_once(filename)}' #{extension_hint(filename)}"

if css_class.nil?
return "<svg><!-- SVG file not found: #{not_found_message}--></svg>".html_safe
Expand Down

0 comments on commit bf39922

Please sign in to comment.