inline_svg 1.6.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/integration_test.yml +47 -0
- data/.github/workflows/rails_6_webpacker_integration_tests.yaml +58 -0
- data/.github/workflows/ruby.yml +20 -0
- data/CHANGELOG.md +31 -2
- data/README.md +8 -4
- data/lib/inline_svg/action_view/helpers.rb +12 -9
- data/lib/inline_svg/cached_asset_file.rb +2 -11
- data/lib/inline_svg/finds_asset_paths.rb +1 -1
- data/lib/inline_svg/propshaft_asset_finder.rb +15 -0
- data/lib/inline_svg/static_asset_finder.rb +4 -2
- data/lib/inline_svg/version.rb +1 -1
- data/lib/inline_svg/webpack_asset_finder.rb +35 -4
- data/lib/inline_svg.rb +3 -0
- data/spec/finds_asset_paths_spec.rb +45 -0
- data/spec/helpers/inline_svg_spec.rb +11 -0
- metadata +7 -6
- data/.travis.yml +0 -8
- data/circle.yml +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23a2c45f1e25e4266196f0e2fc23a4384cb8513be840d2b676ae848b5be1d121
|
4
|
+
data.tar.gz: 8fdb1090f9037ed6c732469ffda28023e200d758533223d4bd9c85b5a20cfb72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3d98f05ba0b9ea222d1b852f87f30584ba4b775d7b6848a2366341e5e85bb6c9912bc1f8441117d129db4d63506d54dcd8ef4d633a5140359e25f5a829a8a1c
|
7
|
+
data.tar.gz: 45eb7d5c8a30f0814e9c775924690825ad3b3ee9c3ada3c9694bf3af46499ababaa1ba81f696514e08dc09aa5ae6520094820fc528ee34fbb307b856dc16b3f4
|
@@ -0,0 +1,47 @@
|
|
1
|
+
name: Integration Tests
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
strategy:
|
10
|
+
matrix:
|
11
|
+
test-branch: [rails5, rails6, rails7]
|
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: Test
|
45
|
+
run: |
|
46
|
+
cd $GITHUB_WORKSPACE/test_app
|
47
|
+
bundle exec rake test
|
@@ -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
|
@@ -0,0 +1,20 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
|
10
|
+
steps:
|
11
|
+
- uses: actions/checkout@v2
|
12
|
+
- name: Set up Ruby 2.6
|
13
|
+
uses: actions/setup-ruby@v1
|
14
|
+
with:
|
15
|
+
ruby-version: 2.6.x
|
16
|
+
- name: Build and test with Rake
|
17
|
+
run: |
|
18
|
+
gem install bundler
|
19
|
+
bundle install --jobs 4 --retry 3
|
20
|
+
bundle exec rake
|
data/CHANGELOG.md
CHANGED
@@ -3,7 +3,31 @@ All notable changes to this project will be documented in this file.
|
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
5
|
## [Unreleased][unreleased]
|
6
|
-
|
6
|
+
|
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).
|
19
|
+
|
20
|
+
## [1.7.1] - 2020-03-17
|
21
|
+
### Fixed
|
22
|
+
- Static Asset Finder uses pathname for compatibility with Sprockets 4+. [#106](https://github.com/jamesmartin/inline_svg/pull/106). Thanks [@subdigital](https://github.com/subdigital)
|
23
|
+
|
24
|
+
## [1.7.0] - 2020-02-13
|
25
|
+
### Added
|
26
|
+
- WebpackAssetFinder serves files from dev server if one is running. [#111](https://github.com/jamesmartin/inline_svg/pull/111). Thanks, [@connorshea](https://github.com/connorshea)
|
27
|
+
|
28
|
+
### Fixed
|
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)
|
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)
|
7
31
|
|
8
32
|
## [1.6.0] - 2019-11-13
|
9
33
|
### Added
|
@@ -220,7 +244,12 @@ transformations](https://github.com/jamesmartin/inline_svg/blob/master/README.md
|
|
220
244
|
### Added
|
221
245
|
- Basic Railtie and view helper to inline SVG documents to Rails views.
|
222
246
|
|
223
|
-
[unreleased]: https://github.com/jamesmartin/inline_svg/compare/v1.
|
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
|
250
|
+
[1.7.1]: https://github.com/jamesmartin/inline_svg/compare/v1.7.0...v1.7.1
|
251
|
+
[1.7.0]: https://github.com/jamesmartin/inline_svg/compare/v1.6.0...v1.7.0
|
252
|
+
[1.6.0]: https://github.com/jamesmartin/inline_svg/compare/v1.5.2...v1.6.0
|
224
253
|
[1.5.2]: https://github.com/jamesmartin/inline_svg/compare/v1.5.1...v1.5.2
|
225
254
|
[1.5.1]: https://github.com/jamesmartin/inline_svg/compare/v1.5.0...v1.5.1
|
226
255
|
[1.5.0]: https://github.com/jamesmartin/inline_svg/compare/v1.4.0...v1.5.0
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Inline SVG
|
2
2
|
|
3
|
-
|
3
|
+
![Unit tests](https://github.com/jamesmartin/inline_svg/workflows/Ruby/badge.svg)
|
4
|
+
![Integration Tests](https://github.com/jamesmartin/inline_svg/workflows/Integration%20Tests/badge.svg)
|
4
5
|
|
5
6
|
Styling a SVG document with CSS for use on the web is most reliably achieved by
|
6
7
|
[adding classes to the document and
|
@@ -11,10 +12,11 @@ then embeds it into a view.
|
|
11
12
|
|
12
13
|
Inline SVG supports:
|
13
14
|
|
14
|
-
- [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))
|
15
|
-
- [Rails 4](http://weblog.rubyonrails.org/2013/6/25/Rails-4-0-final/)
|
16
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))
|
17
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).
|
18
20
|
|
19
21
|
## Changelog
|
20
22
|
|
@@ -97,6 +99,7 @@ key | description
|
|
97
99
|
`preserve_aspect_ratio` | adds a `preserveAspectRatio` attribute to the SVG
|
98
100
|
`aria` | adds common accessibility attributes to the SVG (see [PR #34](https://github.com/jamesmartin/inline_svg/pull/34#issue-152062674) for details)
|
99
101
|
`aria_hidden` | adds the `aria-hidden=true` attribute to the SVG
|
102
|
+
`fallback` | set fallback SVG document
|
100
103
|
|
101
104
|
Example:
|
102
105
|
|
@@ -112,7 +115,8 @@ inline_svg_tag(
|
|
112
115
|
nocomment: true,
|
113
116
|
preserve_aspect_ratio: 'xMaxYMax meet',
|
114
117
|
aria: true,
|
115
|
-
aria_hidden: true
|
118
|
+
aria_hidden: true,
|
119
|
+
fallback: 'fallback-document.svg'
|
116
120
|
)
|
117
121
|
```
|
118
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
|
@@ -69,11 +74,9 @@ module InlineSvg
|
|
69
74
|
end
|
70
75
|
|
71
76
|
def with_asset_finder(asset_finder)
|
72
|
-
|
73
|
-
|
74
|
-
InlineSvg.configuration.asset_finder = asset_finder
|
77
|
+
Thread.current[:inline_svg_asset_finder] = asset_finder
|
75
78
|
output = yield
|
76
|
-
|
79
|
+
Thread.current[:inline_svg_asset_finder] = nil
|
77
80
|
|
78
81
|
output
|
79
82
|
end
|
@@ -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
|
-
|
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,7 +1,9 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
1
3
|
# Naive fallback asset finder for when sprockets >= 3.0 &&
|
2
4
|
# config.assets.precompile = false
|
3
5
|
# Thanks to @ryanswood for the original code:
|
4
|
-
# https://github.com/
|
6
|
+
# https://github.com/jamesmartin/inline_svg/commit/661bbb3bef7d1b4bd6ccd63f5f018305797b9509
|
5
7
|
module InlineSvg
|
6
8
|
class StaticAssetFinder
|
7
9
|
def self.find_asset(filename)
|
@@ -14,7 +16,7 @@ module InlineSvg
|
|
14
16
|
|
15
17
|
def pathname
|
16
18
|
if ::Rails.application.config.assets.compile
|
17
|
-
::Rails.application.assets[@filename].
|
19
|
+
Pathname.new(::Rails.application.assets[@filename].filename)
|
18
20
|
else
|
19
21
|
manifest = ::Rails.application.assets_manifest
|
20
22
|
asset_path = manifest.assets[@filename]
|
data/lib/inline_svg/version.rb
CHANGED
@@ -6,14 +6,45 @@ module InlineSvg
|
|
6
6
|
|
7
7
|
def initialize(filename)
|
8
8
|
@filename = filename
|
9
|
+
@asset_path = URI(Webpacker.manifest.lookup(@filename)).path
|
9
10
|
end
|
10
11
|
|
11
12
|
def pathname
|
12
|
-
|
13
|
-
file_path = Webpacker.instance.manifest.lookup(@filename)
|
14
|
-
return unless public_path && file_path
|
13
|
+
return if @asset_path.blank?
|
15
14
|
|
16
|
-
|
15
|
+
if Webpacker.dev_server.running?
|
16
|
+
dev_server_asset(@asset_path)
|
17
|
+
elsif Webpacker.config.public_path.present?
|
18
|
+
File.join(Webpacker.config.public_path, @asset_path)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def dev_server_asset(file_path)
|
25
|
+
asset = fetch_from_dev_server(file_path)
|
26
|
+
|
27
|
+
begin
|
28
|
+
Tempfile.new(file_path).tap do |file|
|
29
|
+
file.binmode
|
30
|
+
file.write(asset)
|
31
|
+
file.rewind
|
32
|
+
end
|
33
|
+
rescue StandardError => e
|
34
|
+
Rails.logger.error "[inline_svg] Error creating tempfile for #{@filename}: #{e}"
|
35
|
+
raise
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def fetch_from_dev_server(file_path)
|
40
|
+
http = Net::HTTP.new(Webpacker.dev_server.host, Webpacker.dev_server.port)
|
41
|
+
http.use_ssl = Webpacker.dev_server.https?
|
42
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
43
|
+
|
44
|
+
http.request(Net::HTTP::Get.new(file_path)).body
|
45
|
+
rescue StandardError => e
|
46
|
+
Rails.logger.error "[inline_svg] Error fetching #{@filename} from webpack-dev-server: #{e}"
|
47
|
+
raise
|
17
48
|
end
|
18
49
|
end
|
19
50
|
end
|
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: '--></svg><script>alert(1)</script><svg>.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.
|
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:
|
11
|
+
date: 2022-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -129,16 +129,17 @@ executables: []
|
|
129
129
|
extensions: []
|
130
130
|
extra_rdoc_files: []
|
131
131
|
files:
|
132
|
+
- ".github/workflows/integration_test.yml"
|
133
|
+
- ".github/workflows/rails_6_webpacker_integration_tests.yaml"
|
134
|
+
- ".github/workflows/ruby.yml"
|
132
135
|
- ".gitignore"
|
133
136
|
- ".rubocop.yml"
|
134
137
|
- ".rubocop_todo.yml"
|
135
|
-
- ".travis.yml"
|
136
138
|
- CHANGELOG.md
|
137
139
|
- Gemfile
|
138
140
|
- LICENSE.txt
|
139
141
|
- README.md
|
140
142
|
- Rakefile
|
141
|
-
- circle.yml
|
142
143
|
- inline_svg.gemspec
|
143
144
|
- lib/inline_svg.rb
|
144
145
|
- lib/inline_svg/action_view/helpers.rb
|
@@ -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
|
-
|
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.
|
data/.travis.yml
DELETED
data/circle.yml
DELETED