string_tools 1.0.0 → 1.2.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 +4 -4
- data/CHANGELOG.md +37 -1
- data/lib/string_tools/version.rb +1 -1
- data/lib/string_tools.rb +23 -2
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 88f90e3bdd0d61cd67452b28d2d282d3ef821d48785143d750c72998655e1ff5
|
|
4
|
+
data.tar.gz: efd190d4215b001ac24260e1ddd1bf6024a3653acbb4060e8da082b85659c76b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f45484316664f0c72a655a25aa590064585096bbf99823b9068ab63d34b2c7b521b8fbab3b228e8a9ec113546b0919e8bebe97fce9a4e2d7f9dc1d02dd33249f
|
|
7
|
+
data.tar.gz: 00d4e2fe764500b8bb3fb1520a24d20d3dc59c99802178effb925b67906d45da67541fc2be34b506d4ef4e5e57862886de1fe01d43e7382a90cf9e5b6de7de92
|
data/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,25 @@
|
|
|
1
|
-
# v1.
|
|
1
|
+
# v1.2.0
|
|
2
|
+
|
|
3
|
+
* 2024-04-08 [be7e7fd](../../commit/be7e7fd) - __(Andrew N. Shalaev)__ Release v1.2.0
|
|
4
|
+
* 2023-11-29 [393bb13](../../commit/393bb13) - __(GIGrave)__ feature: add media to sanitize rules
|
|
5
|
+
https://jira.railsc.ru/browse/BPC-22916
|
|
6
|
+
|
|
7
|
+
* 2023-11-29 [06eb51e](../../commit/06eb51e) - __(GIGrave)__ Revert "feature: add string_tools config"
|
|
8
|
+
This reverts commit c0b9bf39ec3cf2fce28fe92c7892a0c47593ca09.
|
|
9
|
+
|
|
10
|
+
* 2023-11-29 [d1c00b9](../../commit/d1c00b9) - __(GIGrave)__ Revert "fix: add postgress to drone"
|
|
11
|
+
This reverts commit 33e5698fd48d5edf416df316e3466f9e6c58369f.
|
|
12
|
+
|
|
13
|
+
* 2023-11-02 [33e5698](../../commit/33e5698) - __(GIGrave)__ fix: add postgress to drone
|
|
14
|
+
* 2023-11-02 [c0b9bf3](../../commit/c0b9bf3) - __(GIGrave)__ feature: add string_tools config
|
|
15
|
+
https://jira.railsc.ru/browse/BPC-22612
|
|
16
|
+
|
|
17
|
+
* 2023-10-16 [8ccb54a](../../commit/8ccb54a) - __(ArtemBorodinEvgenyevich)__ Release v1.1.0
|
|
18
|
+
* 2023-08-29 [bed389b](../../commit/bed389b) - __(Terentev Aleksey)__ feat: sanitize links in alt of img tag
|
|
19
|
+
https://jira.railsc.ru/browse/PC4-29908
|
|
20
|
+
|
|
21
|
+
* 2023-08-11 [7848491](../../commit/7848491) - __(Terentev Aleksey)__ feat: add options for sanitize outer links in css
|
|
22
|
+
https://jira.railsc.ru/browse/PC4-29908
|
|
2
23
|
|
|
3
24
|
* 2023-06-15 [503fce2](../../commit/503fce2) - __(Andrew N. Shalaev)__ Release v1.0.0
|
|
4
25
|
* 2023-06-15 [8e9fa48](../../commit/8e9fa48) - __(Andrew N. Shalaev)__ fix: convert to_utf8 correctly, without hidding errors
|
|
@@ -96,6 +117,21 @@ https://jira.railsc.ru/browse/PC4-16353
|
|
|
96
117
|
# v3.0.1
|
|
97
118
|
|
|
98
119
|
|
|
120
|
+
# v1.1.0
|
|
121
|
+
|
|
122
|
+
* 2023-08-29 [bed389b](../../commit/bed389b) - __(Terentev Aleksey)__ feat: sanitize links in alt of img tag
|
|
123
|
+
https://jira.railsc.ru/browse/PC4-29908
|
|
124
|
+
|
|
125
|
+
* 2023-08-11 [7848491](../../commit/7848491) - __(Terentev Aleksey)__ feat: add options for sanitize outer links in css
|
|
126
|
+
https://jira.railsc.ru/browse/PC4-29908
|
|
127
|
+
|
|
128
|
+
# v1.0.0
|
|
129
|
+
|
|
130
|
+
* 2023-06-15 [8e9fa48](../../commit/8e9fa48) - __(Andrew N. Shalaev)__ fix: convert to_utf8 correctly, without hidding errors
|
|
131
|
+
https://jira.railsc.ru/browse/BPC-22244
|
|
132
|
+
|
|
133
|
+
* 2023-06-15 [9bc5cf5](../../commit/9bc5cf5) - __(Andrew N. Shalaev)__ fix: up test env
|
|
134
|
+
|
|
99
135
|
# v0.16.0
|
|
100
136
|
|
|
101
137
|
* 2021-07-16 [5784a91](../../commit/5784a91) - __(Andrew N. Shalaev)__ feature: add support for ruby v2.4
|
data/lib/string_tools/version.rb
CHANGED
data/lib/string_tools.rb
CHANGED
|
@@ -155,6 +155,11 @@ module StringTools
|
|
|
155
155
|
|
|
156
156
|
TAGS_WITHOUT_ATTRIBUTES = %w(b strong i em sup sub ul ol li blockquote br tr u caption thead s).freeze
|
|
157
157
|
|
|
158
|
+
# Public: Sanitize string
|
|
159
|
+
# str - String for sanitize
|
|
160
|
+
# attrs - Hash, custom attributes, defaults empty hash
|
|
161
|
+
# remove_contents - Set of string, tags to be removed
|
|
162
|
+
# protocols - Array of string, protocols using in css properties urls
|
|
158
163
|
def sanitize(str, attrs = {})
|
|
159
164
|
# для корректного обрезания utf строчек режем через mb_chars
|
|
160
165
|
# для защиты от перегрузки парсера пропускаем максимум 1 мегабайт текста
|
|
@@ -162,6 +167,9 @@ module StringTools
|
|
|
162
167
|
# длина по символам с перестраховкой, т.к. латинские символы(теги, например) занимают 1 байт
|
|
163
168
|
str = str.mb_chars.slice(0..(2**19)).to_s
|
|
164
169
|
|
|
170
|
+
remove_contents = attrs.delete(:remove_contents)
|
|
171
|
+
protocols = attrs.delete(:protocols) || []
|
|
172
|
+
|
|
165
173
|
# Мерджим добавочные теги и атрибуты
|
|
166
174
|
attributes = TAGS_WITH_ATTRIBUTES.merge(attrs)
|
|
167
175
|
elements = attributes.keys | TAGS_WITHOUT_ATTRIBUTES
|
|
@@ -173,8 +181,12 @@ module StringTools
|
|
|
173
181
|
str,
|
|
174
182
|
:attributes => attributes,
|
|
175
183
|
:elements => elements,
|
|
176
|
-
:css => {
|
|
177
|
-
|
|
184
|
+
:css => {
|
|
185
|
+
at_rules_with_styles: ['media'],
|
|
186
|
+
properties: Sanitize::Config::RELAXED[:css][:properties],
|
|
187
|
+
protocols: protocols,
|
|
188
|
+
},
|
|
189
|
+
:remove_contents => remove_contents || Set['style', 'script'],
|
|
178
190
|
:allow_comments => false,
|
|
179
191
|
:transformers => transformers
|
|
180
192
|
)
|
|
@@ -191,6 +203,7 @@ module StringTools
|
|
|
191
203
|
normalize_link node, 'href'
|
|
192
204
|
when 'img'
|
|
193
205
|
normalize_link node, 'src'
|
|
206
|
+
remove_links node, 'alt'
|
|
194
207
|
end
|
|
195
208
|
end
|
|
196
209
|
|
|
@@ -202,6 +215,14 @@ module StringTools
|
|
|
202
215
|
rescue Addressable::URI::InvalidURIError
|
|
203
216
|
node.swap node.children
|
|
204
217
|
end
|
|
218
|
+
|
|
219
|
+
def remove_links(node, attr_name)
|
|
220
|
+
return unless node[attr_name]
|
|
221
|
+
|
|
222
|
+
node[attr_name] = node[attr_name].gsub(URI::DEFAULT_PARSER.make_regexp, '').squish
|
|
223
|
+
|
|
224
|
+
node.remove_attribute(attr_name) if node[attr_name].empty?
|
|
225
|
+
end
|
|
205
226
|
end
|
|
206
227
|
|
|
207
228
|
class IframeNormalizer
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: string_tools
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sergey D.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2024-04-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: actionpack
|