icons 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a560ee22eaef4722cc54a4810c2471fa9ee24aa015e609e80ba0c876a207b23
4
- data.tar.gz: f03071f72a369fc8eff35b9fca520ba6108576d361537b97406204b2bec58b42
3
+ metadata.gz: b3020899914efdd03ecf2a92102d477b2f8852aa3688ea09039aaf6d220c0e67
4
+ data.tar.gz: ab8d18495924688b6797bf9c8cc17fb11b0ed2789915dc93cf39fdaf15ae76fd
5
5
  SHA512:
6
- metadata.gz: 1d71a79a568b7a19e1eadb13f846fb571357aa3542026c80683ad623bbeeb6af1c779c8f0634bcdebe445e26d10b8639b5ea8571a15fb1c682b3089f4c3362d3
7
- data.tar.gz: 1ffb7d8ef4233e67b9011028efe012459d3bd2562a1e08a753152523ce850a684165aedf48699433c85cdca2a0481d379d4b9215900dcc5ae85d3fe24b6d69c0
6
+ metadata.gz: 1bac607ff06f7a74a61ad368de35962f29b159d57be17d1181f2a38471fc5c0a6563955015f25690267e41d88acec1344192409d41df0d984617a07c9ac57297
7
+ data.tar.gz: 956af529c206586d7d30d9558e5c36545f2805c5d9a6187eef508e9efa6282ebcd10bca1f1b856186a2a55fd293bd7f6edb5b4ae48c68977dd5951a2693c95c0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- icons (0.10.0)
4
+ icons (0.11.0)
5
5
  nokogiri (~> 1.16, >= 1.16.4)
6
6
 
7
7
  GEM
@@ -119,7 +119,7 @@ CHECKSUMS
119
119
  date (3.5.1) sha256=750d06384d7b9c15d562c76291407d89e368dda4d4fff957eb94962d325a0dc0
120
120
  debug (1.11.1) sha256=2e0b0ac6119f2207a6f8ac7d4a73ca8eb4e440f64da0a3136c30343146e952b6
121
121
  erb (6.0.1) sha256=28ecdd99c5472aebd5674d6061e3c6b0a45c049578b071e5a52c2a7f13c197e5
122
- icons (0.10.0)
122
+ icons (0.11.0)
123
123
  io-console (0.8.2) sha256=d6e3ae7a7cc7574f4b8893b4fca2162e57a825b223a177b7afa236c5ef9814cc
124
124
  irb (1.16.0) sha256=2abe56c9ac947cdcb2f150572904ba798c1e93c890c256f8429981a7675b0806
125
125
  json (2.18.0) sha256=b10506aee4183f5cf49e0efc48073d7b75843ce3782c68dbeb763351c08fd505
@@ -12,6 +12,8 @@ module Icons
12
12
  end
13
13
 
14
14
  def call
15
+ validate_components!
16
+
15
17
  if animated_library?
16
18
  path = animated_icons_path
17
19
  raise Icons::IconNotFound if path.nil?
@@ -25,6 +27,18 @@ module Icons
25
27
 
26
28
  private
27
29
 
30
+ ALLOWED_CHARACTERS = /\A[a-zA-Z0-9_-]+\z/
31
+
32
+ def validate_components!
33
+ raise Icons::IconNotFound, @name unless safe?(@name.to_s)
34
+ raise Icons::IconNotFound, @name unless safe?(@library.to_s)
35
+ raise Icons::IconNotFound, @name unless @variant.nil? || @variant == :"." || safe?(@variant.to_s)
36
+ end
37
+
38
+ def safe?(component)
39
+ component.match?(ALLOWED_CHARACTERS)
40
+ end
41
+
28
42
  def animated_library?
29
43
  @library == :animated
30
44
  end
data/lib/icons/icon.rb CHANGED
@@ -30,11 +30,13 @@ class Icons::Icon
30
30
  # @raise [Icons::IconNotFound] If the icon file does not exist
31
31
  #
32
32
  def svg
33
- Nokogiri::HTML::DocumentFragment.parse(File.read(file_path))
34
- .at_css("svg")
35
- .tap { |svg| attach_attributes(to: svg) }
36
- .to_html
37
- rescue Errno::ENOENT
33
+ svg = Nokogiri::HTML::DocumentFragment.parse(File.read(file_path)).at_css("svg")
34
+ raise Icons::IconNotFound, error_message unless svg
35
+
36
+ attach_attributes(to: svg)
37
+
38
+ svg.to_html
39
+ rescue Errno::ENOENT, Errno::EACCES, Errno::EISDIR
38
40
  raise Icons::IconNotFound, error_message
39
41
  end
40
42
 
data/lib/icons/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Icons
2
- VERSION = "0.10.0"
2
+ VERSION = "0.11.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: icons
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rails Designer