trek 0.1.22 → 0.1.23
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 +4 -4
- data/Gemfile.lock +2 -2
- data/app/components/trek/icon/sprite_component.rb +54 -8
- data/lib/trek/version.rb +1 -1
- data/package.json +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c441a015bd63b8e650c1f39c225b2a40f6a6beebeff6db95d295a84a2c22eae2
|
|
4
|
+
data.tar.gz: 2f7543789a5cb718fdb9a69e6c6f4b9143164a525ea7d5620c5b8816e9d35e01
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1086f69da18c67aa88915c9556c511bca3f30eb981d768078d7f962f8ebf340769be08b0b131f8e873544cd4a152b715a28d7baacabaf19993a685e1c090083c
|
|
7
|
+
data.tar.gz: 8507af27451b4ed7445fe1748e00a246392631d20c2804f213826356fa898a8b29aaf77a716a64233470022e7817209fbd103fbaa98b8482335f59b1279a0f33
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
trek (0.1.
|
|
4
|
+
trek (0.1.23)
|
|
5
5
|
action_policy (~> 0.6)
|
|
6
6
|
actioncable
|
|
7
7
|
acts_as_list (~> 1.1)
|
|
@@ -288,7 +288,7 @@ GEM
|
|
|
288
288
|
mobility (1.3.2)
|
|
289
289
|
i18n (>= 0.6.10, < 2)
|
|
290
290
|
request_store (~> 1.0)
|
|
291
|
-
net-imap (0.6.4)
|
|
291
|
+
net-imap (0.6.4.1)
|
|
292
292
|
date
|
|
293
293
|
net-protocol
|
|
294
294
|
net-pop (0.1.2)
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "rails-html-sanitizer"
|
|
4
|
+
|
|
3
5
|
module Trek
|
|
4
6
|
module Icon
|
|
5
7
|
class SpriteComponent < Trek::Component
|
|
@@ -43,6 +45,56 @@ module Trek
|
|
|
43
45
|
|
|
44
46
|
private
|
|
45
47
|
|
|
48
|
+
|
|
49
|
+
# rubocop:disable Rails/OutputSafety
|
|
50
|
+
def sanitized_svg(key, svg_string)
|
|
51
|
+
sanitizer = Rails::Html::SafeListSanitizer.new
|
|
52
|
+
|
|
53
|
+
# First pass: sanitize svg element with only symbol attributes
|
|
54
|
+
svg_sanitized = sanitizer.sanitize(
|
|
55
|
+
svg_string,
|
|
56
|
+
tags: %w[svg],
|
|
57
|
+
attributes: allowed_symbol_attributes
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
# Second pass: sanitize children with child attributes
|
|
61
|
+
children_sanitized = sanitizer.sanitize(
|
|
62
|
+
svg_string,
|
|
63
|
+
tags: allowed_child_tags,
|
|
64
|
+
attributes: allowed_child_attributes
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
# Extract inner content (children) from the second pass
|
|
68
|
+
inner_content = children_sanitized.sub(/<svg[^>]*>/, "").sub("</svg>", "")
|
|
69
|
+
|
|
70
|
+
# Combine: symbol element from first pass + children from second pass
|
|
71
|
+
svg_sanitized
|
|
72
|
+
.sub("<svg", "<symbol id=\"c-icon-#{key}\"")
|
|
73
|
+
.gsub(/#0{3,6}/, "currentColor")
|
|
74
|
+
.sub(">", ">#{inner_content}")
|
|
75
|
+
.sub("</svg>", "</symbol>")
|
|
76
|
+
.gsub(/[\r\n]+/, "")
|
|
77
|
+
.strip
|
|
78
|
+
.html_safe
|
|
79
|
+
end
|
|
80
|
+
# rubocop:enable Rails/OutputSafety
|
|
81
|
+
|
|
82
|
+
def allowed_child_tags
|
|
83
|
+
%w[path circle rect line polyline polygon ellipse g defs use]
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def allowed_symbol_attributes
|
|
87
|
+
%w[viewbox fill stroke stroke-width stroke-linecap stroke-linejoin stroke-miterlimit]
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def allowed_child_attributes
|
|
91
|
+
%w[
|
|
92
|
+
x x1 x2 y y1 y2 cx cy r rx ry d fill stroke stroke-width height width
|
|
93
|
+
stroke-linecap stroke-linejoin stroke-miterlimit transform
|
|
94
|
+
]
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
#
|
|
46
98
|
# rubocop:disable Rails/OutputSafety
|
|
47
99
|
# rubocop:disable Metrics/MethodLength
|
|
48
100
|
def svg_as_symbol(key)
|
|
@@ -51,14 +103,8 @@ module Trek
|
|
|
51
103
|
return if icon_files.empty?
|
|
52
104
|
|
|
53
105
|
file = File.open(icon_files.last, "rb")
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
.gsub("<svg ", "<symbol id=\"c-icon-#{key}\" ")
|
|
57
|
-
.gsub("</svg", "</symbol")
|
|
58
|
-
.gsub(/#0{3,6}/, "currentColor")
|
|
59
|
-
.gsub(/ ?(height|width|version|xmlns)="([^"]+)"/, "")
|
|
60
|
-
.gsub("xmlns=\"http://www.w3.org/2000/svg\"", "")
|
|
61
|
-
.html_safe
|
|
106
|
+
|
|
107
|
+
sanitized_svg(key, file.read)
|
|
62
108
|
end
|
|
63
109
|
# rubocop:enable Metrics/MethodLength
|
|
64
110
|
# rubocop:enable Rails/OutputSafety
|
data/lib/trek/version.rb
CHANGED
data/package.json
CHANGED