inline_svg 1.7.1 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 923ca3f0952247f48b3346decfe83b44216566a52a2f2bf4a9ba117a2626712b
4
- data.tar.gz: afef4e221a4e7becce12338289eafe79b60138bd2706ec76a51229a588fe8e5d
3
+ metadata.gz: 23a2c45f1e25e4266196f0e2fc23a4384cb8513be840d2b676ae848b5be1d121
4
+ data.tar.gz: 8fdb1090f9037ed6c732469ffda28023e200d758533223d4bd9c85b5a20cfb72
5
5
  SHA512:
6
- metadata.gz: 72bc4f1be354aa23bda0bb62814d194568691b9833e21b8da89594eea213f5ce6fc523ea60c04f19a7e23e546826c98a35ba6cf812579162c70bc6a0905c5d09
7
- data.tar.gz: c0db9494ac8b67ad61c2dfa38f8b6bb64dad204bbf1978cc86f58600d71ee10f977a38ae74b69b7212293f31eec7ebec183c3c90e14aa274605ebe3972626ec7
6
+ metadata.gz: c3d98f05ba0b9ea222d1b852f87f30584ba4b775d7b6848a2366341e5e85bb6c9912bc1f8441117d129db4d63506d54dcd8ef4d633a5140359e25f5a829a8a1c
7
+ data.tar.gz: 45eb7d5c8a30f0814e9c775924690825ad3b3ee9c3ada3c9694bf3af46499ababaa1ba81f696514e08dc09aa5ae6520094820fc528ee34fbb307b856dc16b3f4
@@ -8,7 +8,7 @@ jobs:
8
8
  runs-on: ubuntu-latest
9
9
  strategy:
10
10
  matrix:
11
- test-branch: [rails3, rails4, master, rails6, rails6-webpacker]
11
+ test-branch: [rails5, rails6, rails7]
12
12
  steps:
13
13
  - name: Checkout
14
14
  uses: actions/checkout@v2
@@ -18,10 +18,10 @@ jobs:
18
18
  repository: jamesmartin/inline_svg_test_app
19
19
  ref: ${{ matrix.test-branch }}
20
20
  path: test_app
21
- - name: Set up Ruby 2.6
21
+ - name: Set up Ruby 2.7
22
22
  uses: actions/setup-ruby@v1
23
23
  with:
24
- ruby-version: 2.6.x
24
+ ruby-version: 2.7.x
25
25
  - name: Build local gem
26
26
  run: |
27
27
  gem install bundler
@@ -41,17 +41,6 @@ jobs:
41
41
  run: |
42
42
  cd $GITHUB_WORKSPACE/test_app
43
43
  bundle install --jobs 4 --retry 3
44
- - name: Set up Node.js 12.x
45
- uses: actions/setup-node@v1
46
- with:
47
- node-version: 12.x
48
- if: matrix.test-branch == 'rails6-webpacker'
49
- - name: Generate Webpacker config
50
- run: |
51
- cd $GITHUB_WORKSPACE/test_app
52
- yarn install --check-files
53
- bundle exec rake webpacker:compile
54
- if: matrix.test-branch == 'rails6-webpacker'
55
44
  - name: Test
56
45
  run: |
57
46
  cd $GITHUB_WORKSPACE/test_app
@@ -0,0 +1,58 @@
1
+ name: Rails 6 Webpacker Integration Tests (unreliable)
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+
8
+ runs-on: ubuntu-latest
9
+ strategy:
10
+ matrix:
11
+ test-branch: [rails6-webpacker]
12
+ steps:
13
+ - name: Checkout
14
+ uses: actions/checkout@v2
15
+ - name: Checkout test app
16
+ uses: actions/checkout@v2
17
+ with:
18
+ repository: jamesmartin/inline_svg_test_app
19
+ ref: ${{ matrix.test-branch }}
20
+ path: test_app
21
+ - name: Set up Ruby 2.7
22
+ uses: actions/setup-ruby@v1
23
+ with:
24
+ ruby-version: 2.7.x
25
+ - name: Build local gem
26
+ run: |
27
+ gem install bundler
28
+ bundle install --jobs 4 --retry 3
29
+ bundle exec rake build
30
+ - name: Use the local gem in the test App
31
+ id: uselocalgem
32
+ uses: jacobtomlinson/gha-find-replace@0.1.1
33
+ with:
34
+ find: "gem 'inline_svg'"
35
+ replace: "gem 'inline_svg', path: '${{github.workspace}}'"
36
+ - name: Check local gem in use
37
+ run: |
38
+ test "${{ steps.uselocalgem.outputs.modifiedFiles }}" != "0"
39
+ grep "inline_svg" $GITHUB_WORKSPACE/test_app/Gemfile
40
+ - name: Bundle
41
+ run: |
42
+ cd $GITHUB_WORKSPACE/test_app
43
+ bundle install --jobs 4 --retry 3
44
+ - name: Set up Node.js 16.x
45
+ uses: actions/setup-node@v2
46
+ with:
47
+ node-version: 16
48
+ if: matrix.test-branch == 'rails6-webpacker'
49
+ - name: Generate Webpacker config
50
+ run: |
51
+ cd $GITHUB_WORKSPACE/test_app
52
+ yarn install --check-files
53
+ bundle exec rake webpacker:compile
54
+ if: matrix.test-branch == 'rails6-webpacker'
55
+ - name: Test
56
+ run: |
57
+ cd $GITHUB_WORKSPACE/test_app
58
+ bundle exec rake test
data/CHANGELOG.md CHANGED
@@ -4,7 +4,18 @@ This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
5
  ## [Unreleased][unreleased]
6
6
 
7
- - Nothing
7
+ Nothing.
8
+
9
+ ## [1.8.0] - 2022-01-09
10
+ ### Added
11
+ - Remove deprecation warning for `inline_svg`, as we intend to keep it in 2.0. [#131](https://github.com/jamesmartin/inline_svg/pull/131). Thanks [@DanielJackson-Oslo](https://github.com/DanielJackson-Oslo)
12
+ - Add support for Webpacker 6 beta. [#129](https://github.com/jamesmartin/inline_svg/pull/129). Thanks [@Intrepidd](https://github.com/Intrepidd) and [@tessi](https://github.com/tessi)
13
+ - Add support for Propshaft assets in Rails 7. [#134](https://github.com/jamesmartin/inline_svg/pull/134). Thanks, [@martinzamuner](https://github.com/martinzamuner)
14
+
15
+ ## [1.7.2] - 2020-12-07
16
+ ### Fixed
17
+ - Improve performance of `CachedAssetFile`. [#118](https://github.com/jamesmartin/inline_svg/pull/118). Thanks [@stevendaniels](https://github.com/stevendaniels)
18
+ - Avoid XSS by preventing malicious input of filenames. [#117](https://github.com/jamesmartin/inline_svg/pull/117). Thanks [@pbyrne](https://github.com/pbyrne).
8
19
 
9
20
  ## [1.7.1] - 2020-03-17
10
21
  ### Fixed
@@ -18,7 +29,6 @@ This project adheres to [Semantic Versioning](http://semver.org/).
18
29
  - Using Webpacker and Asset Pipeline in a single App could result in SVGs not being found because the wrong `AssetFinder` was used. [#114](https://github.com/jamesmartin/inline_svg/pull/114). Thanks, [@kylefox](https://github.com/kylefox)
19
30
  - Prevent "EOFError error" when using webpack dev server over HTTPS [#113](https://github.com/jamesmartin/inline_svg/pull/113). Thanks, [@kylefox](https://github.com/kylefox)
20
31
 
21
-
22
32
  ## [1.6.0] - 2019-11-13
23
33
  ### Added
24
34
  - Support Webpack via the new `inline_svg_pack_tag` helper and deprecate `inline_svg` helper in preparation for v2.0.
@@ -234,7 +244,9 @@ transformations](https://github.com/jamesmartin/inline_svg/blob/master/README.md
234
244
  ### Added
235
245
  - Basic Railtie and view helper to inline SVG documents to Rails views.
236
246
 
237
- [unreleased]: https://github.com/jamesmartin/inline_svg/compare/v1.7.1...HEAD
247
+ [unreleased]: https://github.com/jamesmartin/inline_svg/compare/v1.8.0...HEAD
248
+ [1.8.0]: https://github.com/jamesmartin/inline_svg/compare/v1.7.2...v1.8.0
249
+ [1.7.2]: https://github.com/jamesmartin/inline_svg/compare/v1.7.1...v1.7.2
238
250
  [1.7.1]: https://github.com/jamesmartin/inline_svg/compare/v1.7.0...v1.7.1
239
251
  [1.7.0]: https://github.com/jamesmartin/inline_svg/compare/v1.6.0...v1.7.0
240
252
  [1.6.0]: https://github.com/jamesmartin/inline_svg/compare/v1.5.2...v1.6.0
data/README.md CHANGED
@@ -12,10 +12,11 @@ then embeds it into a view.
12
12
 
13
13
  Inline SVG supports:
14
14
 
15
- - [Rails 3](http://weblog.rubyonrails.org/2010/8/29/rails-3-0-it-s-done/) (from [v0.12.0](https://github.com/jamesmartin/inline_svg/releases/tag/v0.12.0))
16
- - [Rails 4](http://weblog.rubyonrails.org/2013/6/25/Rails-4-0-final/)
17
15
  - [Rails 5](http://weblog.rubyonrails.org/2016/6/30/Rails-5-0-final/) (from [v0.10.0](https://github.com/jamesmartin/inline_svg/releases/tag/v0.10.0))
18
16
  - [Rails 6](https://weblog.rubyonrails.org/2019/4/24/Rails-6-0-rc1-released/) with Sprockets or Webpacker (from [v1.5.2](https://github.com/jamesmartin/inline_svg/releases/tag/v1.5.2)).
17
+ - [Rails 7](https://weblog.rubyonrails.org/2021/12/6/Rails-7-0-rc-1-released/) (experimental)
18
+
19
+ Inline SVG no longer officially supports Rails 3 or Rails 4 (although they may still work). In order to reduce the maintenance cost of this project we now follow the [Rails Maintenance Policy](https://guides.rubyonrails.org/maintenance_policy.html).
19
20
 
20
21
  ## Changelog
21
22
 
@@ -98,6 +99,7 @@ key | description
98
99
  `preserve_aspect_ratio` | adds a `preserveAspectRatio` attribute to the SVG
99
100
  `aria` | adds common accessibility attributes to the SVG (see [PR #34](https://github.com/jamesmartin/inline_svg/pull/34#issue-152062674) for details)
100
101
  `aria_hidden` | adds the `aria-hidden=true` attribute to the SVG
102
+ `fallback` | set fallback SVG document
101
103
 
102
104
  Example:
103
105
 
@@ -113,7 +115,8 @@ inline_svg_tag(
113
115
  nocomment: true,
114
116
  preserve_aspect_ratio: 'xMaxYMax meet',
115
117
  aria: true,
116
- aria_hidden: true
118
+ aria_hidden: true,
119
+ fallback: 'fallback-document.svg'
117
120
  )
118
121
  ```
119
122
 
@@ -17,15 +17,20 @@ module InlineSvg
17
17
  end
18
18
 
19
19
  def inline_svg(filename, transform_params={})
20
- ActiveSupport::Deprecation.warn(
21
- '`inline_svg` is deprecated and will be removed from inline_svg 2.0 (use `inline_svg_tag` or `inline_svg_pack_tag` instead)'
22
- )
23
-
24
20
  render_inline_svg(filename, transform_params)
25
21
  end
26
22
 
27
23
  private
28
24
 
25
+ def backwards_compatible_html_escape(filename)
26
+ # html_escape_once was introduced in newer versions of Rails.
27
+ if ERB::Util.respond_to?(:html_escape_once)
28
+ ERB::Util.html_escape_once(filename)
29
+ else
30
+ ERB::Util.html_escape(filename)
31
+ end
32
+ end
33
+
29
34
  def render_inline_svg(filename, transform_params={})
30
35
  begin
31
36
  svg_file = read_svg(filename)
@@ -55,7 +60,7 @@ module InlineSvg
55
60
 
56
61
  def placeholder(filename)
57
62
  css_class = InlineSvg.configuration.svg_not_found_css_class
58
- not_found_message = "'#{filename}' #{extension_hint(filename)}"
63
+ not_found_message = "'#{backwards_compatible_html_escape(filename)}' #{extension_hint(filename)}"
59
64
 
60
65
  if css_class.nil?
61
66
  return "<svg><!-- SVG file not found: #{not_found_message}--></svg>".html_safe
@@ -18,6 +18,7 @@ module InlineSvg
18
18
  @paths = Array(paths).compact.map { |p| Pathname.new(p) }
19
19
  @filters = Array(filters).map { |f| Regexp.new(f) }
20
20
  @assets = @paths.reduce({}) { |assets, p| assets.merge(read_assets(assets, p)) }
21
+ @sorted_asset_keys = assets.keys.sort { |a, b| a.size <=> b.size }
21
22
  end
22
23
 
23
24
  # Public: Finds the named asset and returns the contents as a string.
@@ -39,17 +40,7 @@ module InlineSvg
39
40
  # Returns a String representing the key for the named asset or nil if there
40
41
  # is no match.
41
42
  def key_for_asset(asset_name)
42
- match = all_keys_matching(asset_name).sort do |a, b|
43
- a.string.size <=> b.string.size
44
- end.first
45
- match && match.string
46
- end
47
-
48
- # Internal: Find all potential asset keys matching the given asset name.
49
- #
50
- # Returns an array of MatchData objects for keys matching the asset name.
51
- def all_keys_matching(asset_name)
52
- assets.keys.map { |k| /(#{asset_name})/.match(k.to_s) }.compact
43
+ @sorted_asset_keys.find { |k| k.include?(asset_name) }
53
44
  end
54
45
 
55
46
  # Internal: Recursively descends through current_paths reading each file it
@@ -0,0 +1,15 @@
1
+ module InlineSvg
2
+ class PropshaftAssetFinder
3
+ def self.find_asset(filename)
4
+ new(filename)
5
+ end
6
+
7
+ def initialize(filename)
8
+ @filename = filename
9
+ end
10
+
11
+ def pathname
12
+ ::Rails.application.assets.load_path.find(@filename).path
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module InlineSvg
2
- VERSION = "1.7.1"
2
+ VERSION = "1.8.0"
3
3
  end
@@ -6,7 +6,7 @@ module InlineSvg
6
6
 
7
7
  def initialize(filename)
8
8
  @filename = filename
9
- @asset_path = Webpacker.manifest.lookup(@filename)
9
+ @asset_path = URI(Webpacker.manifest.lookup(@filename)).path
10
10
  end
11
11
 
12
12
  def pathname
data/lib/inline_svg.rb CHANGED
@@ -3,6 +3,7 @@ require "inline_svg/action_view/helpers"
3
3
  require "inline_svg/asset_file"
4
4
  require "inline_svg/cached_asset_file"
5
5
  require "inline_svg/finds_asset_paths"
6
+ require "inline_svg/propshaft_asset_finder"
6
7
  require "inline_svg/static_asset_finder"
7
8
  require "inline_svg/webpack_asset_finder"
8
9
  require "inline_svg/transform_pipeline"
@@ -41,6 +42,8 @@ module InlineSvg
41
42
  def asset_finder=(finder)
42
43
  @asset_finder = if finder.respond_to?(:find_asset)
43
44
  finder
45
+ elsif finder.class.name == "Propshaft::Assembly"
46
+ InlineSvg::PropshaftAssetFinder
44
47
  else
45
48
  # fallback to a naive static asset finder
46
49
  # (sprokects >= 3.0 && config.assets.precompile = false
@@ -45,4 +45,49 @@ describe InlineSvg::FindsAssetPaths do
45
45
  expect(InlineSvg::FindsAssetPaths.by_filename('some-file')).to be_nil
46
46
  end
47
47
  end
48
+
49
+ context "when propshaft finder returns an object which supports only the pathname method" do
50
+ it "returns fully qualified file paths from Propshaft" do
51
+ propshaft = double('PropshaftDouble')
52
+
53
+ expect(propshaft).to receive(:find_asset).with('some-file').
54
+ and_return(double(pathname: Pathname('/full/path/to/some-file')))
55
+
56
+ InlineSvg.configure do |config|
57
+ config.asset_finder = propshaft
58
+ end
59
+
60
+ expect(InlineSvg::FindsAssetPaths.by_filename('some-file')).to eq Pathname('/full/path/to/some-file')
61
+ end
62
+ end
63
+
64
+ context "when webpack finder returns an object with a relative asset path" do
65
+ it "returns the fully qualified file path" do
66
+ webpacker = double('WebpackerDouble')
67
+
68
+ expect(webpacker).to receive(:find_asset).with('some-file').
69
+ and_return(double(filename: Pathname('/full/path/to/some-file')))
70
+
71
+ InlineSvg.configure do |config|
72
+ config.asset_finder = webpacker
73
+ end
74
+
75
+ expect(InlineSvg::FindsAssetPaths.by_filename('some-file')).to eq Pathname('/full/path/to/some-file')
76
+ end
77
+ end
78
+
79
+ context "when webpack finder returns an object with an absolute http asset path" do
80
+ it "returns the fully qualified file path" do
81
+ webpacker = double('WebpackerDouble')
82
+
83
+ expect(webpacker).to receive(:find_asset).with('some-file').
84
+ and_return(double(filename: Pathname('https://my-fancy-domain.test/full/path/to/some-file')))
85
+
86
+ InlineSvg.configure do |config|
87
+ config.asset_finder = webpacker
88
+ end
89
+
90
+ expect(InlineSvg::FindsAssetPaths.by_filename('some-file')).to eq Pathname('https://my-fancy-domain.test/full/path/to/some-file')
91
+ end
92
+ end
48
93
  end
@@ -46,6 +46,17 @@ describe InlineSvg::ActionView::Helpers do
46
46
  expect(output).to be_html_safe
47
47
  end
48
48
 
49
+ it "escapes malicious input" do
50
+ malicious = "--></svg><script>alert(1)</script><svg>.svg"
51
+ allow(InlineSvg::AssetFile).to receive(:named).
52
+ with(malicious).
53
+ and_raise(InlineSvg::AssetFile::FileNotFound.new)
54
+
55
+ output = helper.send(helper_method, malicious)
56
+ expect(output).to eq "<svg><!-- SVG file not found: '--&gt;&lt;/svg&gt;&lt;script&gt;alert(1)&lt;/script&gt;&lt;svg&gt;.svg' --></svg>"
57
+ expect(output).to be_html_safe
58
+ end
59
+
49
60
  it "gives a helpful hint when no .svg extension is provided in the filename" do
50
61
  allow(InlineSvg::AssetFile).to receive(:named).
51
62
  with('missing-file-with-no-extension').
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inline_svg
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Martin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-17 00:00:00.000000000 Z
11
+ date: 2022-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -130,6 +130,7 @@ extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
132
  - ".github/workflows/integration_test.yml"
133
+ - ".github/workflows/rails_6_webpacker_integration_tests.yaml"
133
134
  - ".github/workflows/ruby.yml"
134
135
  - ".gitignore"
135
136
  - ".rubocop.yml"
@@ -147,6 +148,7 @@ files:
147
148
  - lib/inline_svg/finds_asset_paths.rb
148
149
  - lib/inline_svg/id_generator.rb
149
150
  - lib/inline_svg/io_resource.rb
151
+ - lib/inline_svg/propshaft_asset_finder.rb
150
152
  - lib/inline_svg/railtie.rb
151
153
  - lib/inline_svg/static_asset_finder.rb
152
154
  - lib/inline_svg/transform_pipeline.rb
@@ -215,8 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
217
  - !ruby/object:Gem::Version
216
218
  version: '0'
217
219
  requirements: []
218
- rubyforge_project:
219
- rubygems_version: 2.7.6
220
+ rubygems_version: 3.1.2
220
221
  signing_key:
221
222
  specification_version: 4
222
223
  summary: Embeds an SVG document, inline.