meta-tags 2.24.0 → 2.25.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
- checksums.yaml.gz.sig +0 -0
- data/AGENTS.md +4 -0
- data/CHANGELOG.md +26 -0
- data/README.md +1 -1
- data/certs/kpumuk.pem +7 -7
- data/lib/meta_tags/content_tag.rb +1 -1
- data/lib/meta_tags/controller_helper.rb +22 -3
- data/lib/meta_tags/meta_tags_collection.rb +18 -22
- data/lib/meta_tags/tag.rb +25 -1
- data/lib/meta_tags/text_normalizer.rb +77 -21
- data/lib/meta_tags/version.rb +1 -1
- data/lib/meta_tags.rb +0 -1
- data/sig/_private/rails_support.rbs +2 -0
- data/sig/lib/meta_tags/configuration.rbs +2 -2
- data/sig/lib/meta_tags/controller_helper.rbs +6 -0
- data/sig/lib/meta_tags/rails_interfaces.rbs +2 -0
- data/sig/lib/meta_tags/tag.rbs +2 -0
- data/sig/lib/meta_tags/text_normalizer.rbs +6 -3
- data/sig/lib/meta_tags/view_helper.rbs +1 -1
- data.tar.gz.sig +0 -0
- metadata +19 -18
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7c6d1c85b9d903246781e74a1439f526c945fdc7ef0efab54b8ea1398e708dac
|
|
4
|
+
data.tar.gz: d3ab4d7ed33f4dd83a9c73d9b7da9d4ae40685b19affd790a2c393fc7f0aba8f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7db6e7d7fff2d445eb937d6aa4ebd86f75e79fa444f3e19d5884bfdf0f4c434e497d14ca66911f102453d74f82aaa05ff508021e517f2ce2248cebcb36c23d77
|
|
7
|
+
data.tar.gz: 6c3a4d47c58ea86f28d1fdb060c5eed7466038c2b76100b588b542bcfd42ce3ecbfab430fcb6c854adf0ee53c5b5270248f70c6de77d24d85db11ee27dfb2a6b
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/AGENTS.md
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
- Document substantial user-visible changes, including features, bug fixes, performance improvements, and compatibility changes, in the `Unreleased` section of `CHANGELOG.md`. Describe the effect on users and follow the existing section style.
|
|
4
|
+
- Documentation-only edits, test-only edits, and internal refactors with no user-visible effect do not need a changelog entry.
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 2.25.0 (November 29, 2026) [☰](https://github.com/kpumuk/meta-tags/compare/v2.24.0...v2.25.0)
|
|
6
|
+
|
|
7
|
+
Bugfixes:
|
|
8
|
+
|
|
9
|
+
- Allowed `Time`, `Date`, `DateTime`, and `ActiveSupport::TimeWithZone` values in `title_tag_attributes` in RBS, including nested `data` attributes, to match the existing runtime rendering ([456](https://github.com/kpumuk/meta-tags/pull/456)).
|
|
10
|
+
- Made `skip_canonical_links_on_noindex` treat a standalone robots `none` directive as equivalent to `noindex, nofollow`, while leaving valued directives such as `max-image-preview:none` unaffected ([426](https://github.com/kpumuk/meta-tags/pull/426)).
|
|
11
|
+
- Made the `lowercase` title option transform decoded text instead of raw HTML, so numeric character references are lowercased and case-sensitive named entities retain their intended symbols ([427](https://github.com/kpumuk/meta-tags/pull/427)).
|
|
12
|
+
- Normalized site-only title fallbacks for mirrored titles and the `title` helper, applying text cleanup and title length limits while preserving site casing ([450](https://github.com/kpumuk/meta-tags/pull/450)).
|
|
13
|
+
- Allowed an explicit `nil` title in the `title` helper RBS signature, matching the existing runtime behavior ([428](https://github.com/kpumuk/meta-tags/pull/428)).
|
|
14
|
+
- Allowed `nil` for `keywords_limit` in RBS to match the existing unlimited-keywords runtime behavior ([451](https://github.com/kpumuk/meta-tags/pull/451)).
|
|
15
|
+
- Applied controller `@page_title`, `@page_description`, and `@page_keywords` metadata during `render_to_string`, matching ordinary template rendering ([454](https://github.com/kpumuk/meta-tags/pull/454)).
|
|
16
|
+
- Compared crawler names case-insensitively in robots handling. Robots helpers now apply `follow` over `nofollow` and `noindex` over `index` when targets differ only in case, using the first spelling supplied, and `skip_canonical_links_on_noindex` recognizes mixed-case custom `robots`, `googlebot`, and `bingbot` tags such as `"Robots" => "noindex"` ([457](https://github.com/kpumuk/meta-tags/pull/457)).
|
|
17
|
+
- Made the privileged Dependabot lockfile workflow match artifact names literally against the pull request's existing lockfiles, so names starting with a dash can no longer bypass the allowlist ([458](https://github.com/kpumuk/meta-tags/pull/458)).
|
|
18
|
+
- Renewed the gem signing certificate, which expired on September 29, 2026, so releases can be signed again and installed with a RubyGems trust policy such as `gem install meta-tags -P MediumSecurity`. A weekly check now fails 30 days before the certificate expires ([464](https://github.com/kpumuk/meta-tags/pull/464)).
|
|
19
|
+
- Dropped the contents of `<script>` and `<style>` elements when stripping HTML from titles, descriptions, and keywords, matching Rails' `strip_tags`. Inline scripts, JSON blobs, and CSS no longer appear in `<meta name="description">` or mirrored tags such as `og:description`. As in browsers, an unclosed `<script>` or `<style>` hides the rest of the value ([465](https://github.com/kpumuk/meta-tags/pull/465)).
|
|
20
|
+
- Dropped attribute names that are blank once converted to a string, such as `""`, `" "`, or `:" "`, from `icon`, `alternate`, and `title_tag_attributes` hashes and the `data` and `aria` hashes nested in them. Rails 6.1 through 7.2, 8.0 before 8.0.5.2, and 8.1 before 8.1.4.1 render such a name as a nameless attribute, so its value could be parsed as further attributes, such as an event handler (CVE-2026-33168, GHSA-68p9-83h6-5wpj). Output on patched Rails versions is unchanged ([470](https://github.com/kpumuk/meta-tags/pull/470)).
|
|
21
|
+
|
|
22
|
+
Changes:
|
|
23
|
+
|
|
24
|
+
- Ruby 3.2 is now the minimum supported version. Ruby 3.0 and 3.1 are no longer supported ([444](https://github.com/kpumuk/meta-tags/pull/444)).
|
|
25
|
+
- Rails 6.1 is now the minimum version the gem declares, matching the documented and tested support. Rails 6.0 was never tested; on Rails 6.0, Bundler keeps resolving `meta-tags` to 2.24.0, and requiring a newer version fails to resolve because it depends on `actionpack >= 6.1.0` ([469](https://github.com/kpumuk/meta-tags/pull/469)).
|
|
26
|
+
- Avoided HTML parsing for plain UTF-8 ASCII metadata text while preserving normalization and escaping behavior ([452](https://github.com/kpumuk/meta-tags/pull/452)).
|
|
27
|
+
- Avoided normalizing or validating discarded keyword suffixes in large arrays with a positive character limit, while keeping small arrays on the eager path ([453](https://github.com/kpumuk/meta-tags/pull/453)).
|
|
28
|
+
- Bounded the HTML parsing cost of long `title`, `description`, and `keywords` values when a positive character limit applies: only the part of each value before its 2,049th `<` is read at the default limits (four times the limit for limits above 512), so rendering a large HTML body as a description no longer slows down with the amount of markup in it. Text behind more markup than that is ignored, and every `<` counts, including those inside scripts. Long attribute values such as inline images are read whole. Unlimited configurations (`nil` or `0` limits) still read the whole value ([468](https://github.com/kpumuk/meta-tags/pull/468)).
|
|
29
|
+
- Hardened the release workflow: it installs dependencies before building the gem and installs them frozen to the committed lockfile, so publishing never uses a fresh dependency resolution ([422](https://github.com/kpumuk/meta-tags/pull/422), [471](https://github.com/kpumuk/meta-tags/pull/471)).
|
|
30
|
+
|
|
5
31
|
## 2.24.0 (September 1, 2026) [☰](https://github.com/kpumuk/meta-tags/compare/v2.23.0...v2.24.0)
|
|
6
32
|
|
|
7
33
|
Features:
|
data/README.md
CHANGED
|
@@ -16,7 +16,7 @@ It supports the metadata layer of search engine optimization (SEO), especially f
|
|
|
16
16
|
The MetaTags main branch fully supports Ruby on Rails 6.1+ and is tested against all major Ruby on Rails releases.
|
|
17
17
|
|
|
18
18
|
> [!NOTE]
|
|
19
|
-
>
|
|
19
|
+
> MetaTags requires Ruby 3.2+ and Ruby on Rails 6.1+. Older Rails release series that MetaTags still supports may no longer receive security fixes from the Rails team; see the [Rails maintenance policy](https://rubyonrails.org/maintenance).
|
|
20
20
|
|
|
21
21
|
> [!IMPORTANT]
|
|
22
22
|
> MetaTags manages HTML head metadata. It does not generate structured data / JSON-LD, `robots.txt`, sitemaps, internal links, or page content.
|
data/certs/kpumuk.pem
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
-----BEGIN CERTIFICATE-----
|
|
2
2
|
MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQsFADA/MQ8wDQYDVQQDDAZrcHVt
|
|
3
3
|
dWsxFjAUBgoJkiaJk/IsZAEZFgZrcHVtdWsxFDASBgoJkiaJk/IsZAEZFgRpbmZv
|
|
4
|
-
|
|
4
|
+
MB4XDTI2MTEyODE0MzU1MloXDTI3MTEyODE0MzU1MlowPzEPMA0GA1UEAwwGa3B1
|
|
5
5
|
bXVrMRYwFAYKCZImiZPyLGQBGRYGa3B1bXVrMRQwEgYKCZImiZPyLGQBGRYEaW5m
|
|
6
6
|
bzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALw2YroZc+IT+rs8NuPu
|
|
7
7
|
c13DelrxrpAgPEu1zuRb3l7WaHRNWA4TyS8Z6Aa1G2O+FdUZNMW1n7IwP/QMJ9Mz
|
|
@@ -12,10 +12,10 @@ pJ3vGgO2sh5GvJFOPk1Vlur2nX9ZFznPEP1CEAQ+NFrmKRt355Z5sgOkAojSGnIL
|
|
|
12
12
|
/1sCAwEAAaN3MHUwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFPa4
|
|
13
13
|
VFc1YOlV1u/7EGTwMCAk8YE9MB0GA1UdEQQWMBSBEmtwdW11a0BrcHVtdWsuaW5m
|
|
14
14
|
bzAdBgNVHRIEFjAUgRJrcHVtdWtAa3B1bXVrLmluZm8wDQYJKoZIhvcNAQELBQAD
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
ggEBAGSpWh2R8DV3hZgcukoPFrCVnRAHHYeQz0BhB7c/it2pITgy6F76HFcJLvHg
|
|
16
|
+
OoLg0EeOyc/ClcBN8DCl+ZkHVkqEy6FXiURDQyTprsNbrYfaDcy8kaHJZwhgC9Xq
|
|
17
|
+
Osv/1yVtXOP6L4C42TzrI02zFquFmdKYqsi3KU/dEOiyTS9mktDE3Ha7PLq9lIB8
|
|
18
|
+
13+QKCjpJUMGlZ1jv8Bi9FkvneDdiH9ACt0T0/q8gh3RW3y0M/4RBD2lIFzbsGns
|
|
19
|
+
yrtanYI2gZSjOVJob8j8cnfTbptGf1KRwp6r6xYNAP4vjY5/6UbcY03lHjluHGqB
|
|
20
|
+
OFHUoH7OjqY3Uh5+KobrRnn9QMY=
|
|
21
21
|
-----END CERTIFICATE-----
|
|
@@ -9,7 +9,7 @@ module MetaTags
|
|
|
9
9
|
# @param view [ActionView::Base] instance of a Rails view.
|
|
10
10
|
# @return [String] HTML string for the tag.
|
|
11
11
|
def render(view)
|
|
12
|
-
view.content_tag(name, attributes[:content], serialize_iso8601_attributes(attributes.except(:content)))
|
|
12
|
+
view.content_tag(name, attributes[:content], drop_blank_attribute_names(serialize_iso8601_attributes(attributes.except(:content))))
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
15
|
end
|
|
@@ -17,9 +17,19 @@ module MetaTags
|
|
|
17
17
|
# @yield optional block forwarded to +render+.
|
|
18
18
|
# @yieldreturn [Object] result of the render block.
|
|
19
19
|
def render(*args, &block)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
set_meta_tags_from_instance_variables
|
|
21
|
+
|
|
22
|
+
super
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Processes controller instance-variable metadata before rendering to a string.
|
|
26
|
+
#
|
|
27
|
+
# @param args [Array<Object>] positional arguments forwarded to +render_to_string+.
|
|
28
|
+
# @param block [Proc, nil] optional block forwarded to +render_to_string+.
|
|
29
|
+
# @yield optional block forwarded to +render_to_string+.
|
|
30
|
+
# @yieldreturn [Object] result of the render block.
|
|
31
|
+
def render_to_string(*args, &block)
|
|
32
|
+
set_meta_tags_from_instance_variables
|
|
23
33
|
|
|
24
34
|
super
|
|
25
35
|
end
|
|
@@ -38,5 +48,14 @@ module MetaTags
|
|
|
38
48
|
@meta_tags ||= MetaTagsCollection.new
|
|
39
49
|
end
|
|
40
50
|
protected :meta_tags
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
|
|
54
|
+
# Copies controller instance-variable metadata into the collection.
|
|
55
|
+
def set_meta_tags_from_instance_variables
|
|
56
|
+
meta_tags[:title] = @page_title if defined?(@page_title) && @page_title
|
|
57
|
+
meta_tags[:keywords] = @page_keywords if defined?(@page_keywords) && @page_keywords
|
|
58
|
+
meta_tags[:description] = @page_description if defined?(@page_description) && @page_description
|
|
59
|
+
end
|
|
41
60
|
end
|
|
42
61
|
end
|
|
@@ -72,7 +72,7 @@ module MetaTags
|
|
|
72
72
|
def page_title(defaults = {})
|
|
73
73
|
with_defaults(defaults) do
|
|
74
74
|
site = extract(:site)
|
|
75
|
-
extract_full_title.presence || site
|
|
75
|
+
extract_full_title.presence || TextNormalizer.normalize_title(site, [], "")
|
|
76
76
|
end
|
|
77
77
|
end
|
|
78
78
|
|
|
@@ -96,32 +96,22 @@ module MetaTags
|
|
|
96
96
|
# @return [String] page title.
|
|
97
97
|
def extract_full_title
|
|
98
98
|
site_title = extract(:site) || ""
|
|
99
|
+
lowercase = extract(:lowercase) == true
|
|
99
100
|
title = extract_title
|
|
100
101
|
separator = extract_separator
|
|
101
102
|
reverse = extract(:reverse) == true
|
|
102
103
|
|
|
103
|
-
TextNormalizer.normalize_title(site_title, title, separator, reverse)
|
|
104
|
+
TextNormalizer.normalize_title(site_title, title, separator, reverse: reverse, lowercase: lowercase)
|
|
104
105
|
end
|
|
105
106
|
|
|
106
107
|
# Extracts page title as an array of segments without site title and separators.
|
|
107
108
|
#
|
|
108
109
|
# @return [Array<String>] segments of page title.
|
|
109
110
|
def extract_title
|
|
110
|
-
lowercase = extract(:lowercase) == true
|
|
111
111
|
title = extract(:title).presence
|
|
112
112
|
return [] unless title
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
if lowercase
|
|
116
|
-
return title.map do |segment|
|
|
117
|
-
string = String.try_convert(segment)
|
|
118
|
-
raise ArgumentError, "Expected a string or an object that implements #to_str" unless string
|
|
119
|
-
|
|
120
|
-
string.downcase
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
title
|
|
114
|
+
Array(title)
|
|
125
115
|
end
|
|
126
116
|
|
|
127
117
|
# Extracts title separator as a string.
|
|
@@ -160,15 +150,20 @@ module MetaTags
|
|
|
160
150
|
def noindex?
|
|
161
151
|
contents = robots.values
|
|
162
152
|
property_tags = MetaTags.config.property_tags.map(&:to_s)
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
153
|
+
meta_tags.each do |key, values|
|
|
154
|
+
# Crawler names are case-insensitive, but rendering keeps the key's spelling.
|
|
155
|
+
key = key.to_s
|
|
156
|
+
next unless %w[robots googlebot bingbot].any? { |bot| key.casecmp?(bot) }
|
|
157
|
+
next if values.is_a?(Hash) || property_tags.include?(key)
|
|
166
158
|
|
|
167
159
|
contents.concat(Array(values))
|
|
168
160
|
end
|
|
169
161
|
|
|
170
162
|
contents.any? do |content|
|
|
171
|
-
content.to_s.split(",").any?
|
|
163
|
+
content.to_s.split(",").any? do |directive|
|
|
164
|
+
directive = directive.strip
|
|
165
|
+
directive.casecmp?("noindex") || directive.casecmp?("none")
|
|
166
|
+
end
|
|
172
167
|
end
|
|
173
168
|
end
|
|
174
169
|
|
|
@@ -282,19 +277,20 @@ module MetaTags
|
|
|
282
277
|
end
|
|
283
278
|
end
|
|
284
279
|
|
|
285
|
-
# Records a robots directive unless it has already been set for the same
|
|
280
|
+
# Records a robots directive unless it has already been set for the same
|
|
281
|
+
# crawler. Crawler names are compared case-insensitively, while the
|
|
282
|
+
# directive is recorded under the first spelling supplied.
|
|
286
283
|
#
|
|
287
284
|
# @param result [Hash{String => Array<String>}] robots directives grouped by tag name.
|
|
288
285
|
# @param name [String] robots tag name.
|
|
289
286
|
# @param value [String] robots directive value.
|
|
290
|
-
# @param processed [Set<String>] names already recorded in this pass.
|
|
287
|
+
# @param processed [Set<String>] downcased names already recorded in this pass.
|
|
291
288
|
# @return [void]
|
|
292
289
|
def apply_robots_value(result, name, value, processed)
|
|
293
290
|
name = name.to_s
|
|
294
|
-
return
|
|
291
|
+
return unless processed.add?(name.downcase)
|
|
295
292
|
|
|
296
293
|
result[name] << value
|
|
297
|
-
processed << name
|
|
298
294
|
end
|
|
299
295
|
end
|
|
300
296
|
end
|
data/lib/meta_tags/tag.rb
CHANGED
|
@@ -19,11 +19,35 @@ module MetaTags
|
|
|
19
19
|
# @param view [ActionView::Base] instance of a Rails view.
|
|
20
20
|
# @return [String] HTML string for the tag.
|
|
21
21
|
def render(view)
|
|
22
|
-
view.tag(name, serialize_iso8601_attributes(attributes), MetaTags.config.open_meta_tags?)
|
|
22
|
+
view.tag(name, drop_blank_attribute_names(serialize_iso8601_attributes(attributes)), MetaTags.config.open_meta_tags?)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
protected
|
|
26
26
|
|
|
27
|
+
# Removes attributes whose names are blank once converted to a String,
|
|
28
|
+
# including names nested under +data+ and +aria+. Rails 6.1 through 7.2,
|
|
29
|
+
# 8.0 before 8.0.5.2, and 8.1 before 8.1.4.1 render such a name as a
|
|
30
|
+
# nameless attribute, which lets its value be parsed as further
|
|
31
|
+
# attributes (CVE-2026-33168, GHSA-68p9-83h6-5wpj). Patched Rails drops
|
|
32
|
+
# these names too.
|
|
33
|
+
#
|
|
34
|
+
# @param attributes [Hash] HTML tag attributes.
|
|
35
|
+
# @return [Hash] HTML tag attributes without blank names.
|
|
36
|
+
def drop_blank_attribute_names(attributes)
|
|
37
|
+
# @type var result: Hash[String | Symbol, untyped]
|
|
38
|
+
result = {}
|
|
39
|
+
attributes.each do |key, value|
|
|
40
|
+
name = key.to_s
|
|
41
|
+
next if name.blank?
|
|
42
|
+
|
|
43
|
+
if value.is_a?(Hash) && (name == "data" || name == "aria")
|
|
44
|
+
value = value.reject { |nested_key, _| nested_key.to_s.blank? }
|
|
45
|
+
end
|
|
46
|
+
result[key] = value
|
|
47
|
+
end
|
|
48
|
+
result
|
|
49
|
+
end
|
|
50
|
+
|
|
27
51
|
# Serializes attribute values that support ISO 8601 formatting.
|
|
28
52
|
#
|
|
29
53
|
# @param attributes [Hash] HTML tag attributes.
|
|
@@ -11,13 +11,16 @@ module MetaTags
|
|
|
11
11
|
# @param title [Array<String>] title segments.
|
|
12
12
|
# @param separator [String] a string to join title parts with.
|
|
13
13
|
# @param reverse [Boolean] whether title should be reversed.
|
|
14
|
+
# @param lowercase [Boolean] whether title segments should be lowercased.
|
|
14
15
|
# @return [String] title with HTML tags removed.
|
|
15
|
-
def normalize_title(site_title, title, separator, reverse
|
|
16
|
-
|
|
16
|
+
def normalize_title(site_title, title, separator, reverse: false, lowercase: false)
|
|
17
|
+
limit = MetaTags.config.title_limit
|
|
18
|
+
clean_title = cleanup_strings(title, limit: limit)
|
|
19
|
+
clean_title.each(&:downcase!) if lowercase
|
|
17
20
|
clean_title.reverse! if reverse
|
|
18
21
|
|
|
19
|
-
site_title = cleanup_string(site_title)
|
|
20
|
-
separator = cleanup_string(separator, strip: false)
|
|
22
|
+
site_title = cleanup_string(site_title, limit: limit)
|
|
23
|
+
separator = cleanup_string(separator, strip: false, limit: limit)
|
|
21
24
|
|
|
22
25
|
# Truncate title and site title
|
|
23
26
|
site_title, clean_title = truncate_title(site_title, clean_title, separator)
|
|
@@ -41,10 +44,11 @@ module MetaTags
|
|
|
41
44
|
# description could be another object not a string, but since it probably
|
|
42
45
|
# serves the same purpose, we can ask it to convert itself to a string
|
|
43
46
|
# and continue from there
|
|
44
|
-
|
|
47
|
+
limit = MetaTags.config.description_limit
|
|
48
|
+
description = cleanup_string(description, limit: limit)
|
|
45
49
|
return "" if description.blank?
|
|
46
50
|
|
|
47
|
-
truncate(description,
|
|
51
|
+
truncate(description, limit)
|
|
48
52
|
end
|
|
49
53
|
|
|
50
54
|
# Normalize keywords value.
|
|
@@ -52,14 +56,22 @@ module MetaTags
|
|
|
52
56
|
# @param keywords [String, Array<String>] list of keywords as a string or Array.
|
|
53
57
|
# @return [String] list of keywords joined with comma, with tags removed.
|
|
54
58
|
def normalize_keywords(keywords)
|
|
55
|
-
|
|
59
|
+
limit = MetaTags.config.keywords_limit
|
|
60
|
+
lowercase = MetaTags.config.keywords_lowercase
|
|
61
|
+
keywords = Array(keywords).flatten
|
|
62
|
+
keywords = keywords.lazy if keywords.size > 32 && limit.to_i > 0
|
|
63
|
+
keywords = keywords.filter_map do |keyword|
|
|
64
|
+
string = cleanup_string(keyword, limit: limit)
|
|
65
|
+
next if string.blank?
|
|
66
|
+
|
|
67
|
+
string.downcase! if lowercase
|
|
68
|
+
string
|
|
69
|
+
end
|
|
56
70
|
return "" if keywords.blank?
|
|
57
71
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
keywords = truncate_array(keywords, MetaTags.config.keywords_limit, separator)
|
|
62
|
-
safe_join(keywords, separator)
|
|
72
|
+
separator = cleanup_string MetaTags.config.keywords_separator, strip: false, limit: limit
|
|
73
|
+
keywords = truncate_array(keywords, limit, separator).to_a
|
|
74
|
+
keywords.empty? ? "" : safe_join(keywords, separator)
|
|
63
75
|
end
|
|
64
76
|
|
|
65
77
|
# Easy way to get access to Rails helpers.
|
|
@@ -75,8 +87,23 @@ module MetaTags
|
|
|
75
87
|
# @return [String] HTML-safe string with no HTML tags.
|
|
76
88
|
def strip_tags(string)
|
|
77
89
|
if defined?(Loofah)
|
|
78
|
-
#
|
|
79
|
-
|
|
90
|
+
# Only plain UTF-8 text can skip parsing without encoding or control changes.
|
|
91
|
+
if string.encoding == Encoding::UTF_8 && string.ascii_only? && !string.match?(/[<&\x00-\x08\x0B-\x1F\x7F]/)
|
|
92
|
+
# Loofah returns US-ASCII for an empty fragment, UTF-8 for other text.
|
|
93
|
+
encoding = string.empty? ? Encoding::US_ASCII : Encoding::UTF_8
|
|
94
|
+
# Do not retain the caller's HTML-safety flag or mutate its string.
|
|
95
|
+
return String.new(string, encoding: encoding)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Instead of strip_tags we will use Loofah to strip tags from now on.
|
|
99
|
+
# Like Rails' strip_tags, drop script and style source, including the
|
|
100
|
+
# rest of the value after an unclosed <script> or <style>.
|
|
101
|
+
fragment = Loofah.fragment(string)
|
|
102
|
+
# Separate queries stay linear: DocumentFragment#css queries each
|
|
103
|
+
# top-level node, and an XPath union is quadratic in its matches.
|
|
104
|
+
fragment.xpath(".//script").remove
|
|
105
|
+
fragment.xpath(".//style").remove
|
|
106
|
+
fragment.text(encode_special_chars: false)
|
|
80
107
|
else
|
|
81
108
|
helpers.strip_tags(string)
|
|
82
109
|
end
|
|
@@ -96,15 +123,20 @@ module MetaTags
|
|
|
96
123
|
|
|
97
124
|
# Removes HTML tags and squashes down all the spaces.
|
|
98
125
|
#
|
|
126
|
+
# With a positive +limit+, markup beyond what a value truncated to +limit+
|
|
127
|
+
# can use is not parsed. See #truncate_markup.
|
|
128
|
+
#
|
|
99
129
|
# @param string [String, nil] input string.
|
|
100
130
|
# @param strip [Boolean] whether to trim leading and trailing whitespace.
|
|
131
|
+
# @param limit [Integer, nil] number of characters the result will be
|
|
132
|
+
# truncated to, or +nil+ or 0 to parse the whole input.
|
|
101
133
|
# @return [String] input string with no HTML tags and consecutive
|
|
102
134
|
# whitespace characters squashed into a single space.
|
|
103
|
-
def cleanup_string(string, strip: true)
|
|
135
|
+
def cleanup_string(string, strip: true, limit: nil)
|
|
104
136
|
return "" if string.nil?
|
|
105
137
|
raise ArgumentError, "Expected a string or an object that implements #to_str" unless string.respond_to?(:to_str)
|
|
106
138
|
|
|
107
|
-
s = strip_tags(string.to_str)
|
|
139
|
+
s = strip_tags(truncate_markup(string.to_str, limit))
|
|
108
140
|
s = s.dup if s.frozen?
|
|
109
141
|
s.gsub!(/\s+/, " ")
|
|
110
142
|
s.strip! if strip
|
|
@@ -116,10 +148,11 @@ module MetaTags
|
|
|
116
148
|
#
|
|
117
149
|
# @param strings [String, Array<String>] input string(s).
|
|
118
150
|
# @param strip [Boolean] whether to trim leading and trailing whitespace.
|
|
151
|
+
# @param limit [Integer, nil] number of characters each result will be truncated to.
|
|
119
152
|
# @return [Array<String>] clean strings.
|
|
120
153
|
# @see cleanup_string
|
|
121
|
-
def cleanup_strings(strings, strip: true)
|
|
122
|
-
strings = Array(strings).flatten.map! { |s| cleanup_string(s, strip: strip) }
|
|
154
|
+
def cleanup_strings(strings, strip: true, limit: nil)
|
|
155
|
+
strings = Array(strings).flatten.map! { |s| cleanup_string(s, strip: strip, limit: limit) }
|
|
123
156
|
strings.reject!(&:blank?)
|
|
124
157
|
strings
|
|
125
158
|
end
|
|
@@ -144,15 +177,15 @@ module MetaTags
|
|
|
144
177
|
|
|
145
178
|
# Truncates an array of strings to a specific limit.
|
|
146
179
|
#
|
|
147
|
-
# @param string_array [
|
|
180
|
+
# @param string_array [Enumerable<String>] input strings.
|
|
148
181
|
# @param limit [Integer, nil] number of characters to truncate to.
|
|
149
182
|
# @param separator [String] separator that will be used to join the array later.
|
|
150
|
-
# @return [
|
|
183
|
+
# @return [Enumerable<String>] truncated array, or the original input if unlimited.
|
|
151
184
|
def truncate_array(string_array, limit = nil, separator = "")
|
|
152
185
|
return string_array if limit.nil? || limit <= 0
|
|
153
186
|
|
|
154
187
|
length = 0
|
|
155
|
-
preserve_items =
|
|
188
|
+
preserve_items = MetaTags.config.truncate_array_items_at_boundaries
|
|
156
189
|
result = [] # : Array[String]
|
|
157
190
|
|
|
158
191
|
string_array.each do |string|
|
|
@@ -175,6 +208,29 @@ module MetaTags
|
|
|
175
208
|
|
|
176
209
|
private
|
|
177
210
|
|
|
211
|
+
# Cuts +string+ before its <tt>([limit * 4, 2048].max + 1)</tt>th "<", so the
|
|
212
|
+
# number of tags, comments, and other markup the HTML parser handles, which
|
|
213
|
+
# drives its cost, does not grow with the size of a value that will be
|
|
214
|
+
# truncated to +limit+ characters. Text before a "<" is complete, so the cut
|
|
215
|
+
# never splits a character or a character reference, and long attribute
|
|
216
|
+
# values, scripts, and runs of text or whitespace are kept whole. Every "<"
|
|
217
|
+
# counts, including those inside scripts, comments, and attribute values,
|
|
218
|
+
# because telling them apart takes the parser itself.
|
|
219
|
+
#
|
|
220
|
+
# @param string [String] input string.
|
|
221
|
+
# @param limit [Integer, nil] number of characters the result will be truncated to.
|
|
222
|
+
# @return [String] the input, or a prefix of it when it has too much markup.
|
|
223
|
+
def truncate_markup(string, limit)
|
|
224
|
+
return string if limit.to_i <= 0 || !string.encoding.ascii_compatible?
|
|
225
|
+
|
|
226
|
+
markup_limit = [limit.to_i * 4, 2048].max
|
|
227
|
+
return string if string.count("<") <= markup_limit
|
|
228
|
+
|
|
229
|
+
offset = 0
|
|
230
|
+
markup_limit.times { offset = string.byteindex("<", offset).to_i + 1 }
|
|
231
|
+
string.byteslice(0, string.byteindex("<", offset).to_i).to_s
|
|
232
|
+
end
|
|
233
|
+
|
|
178
234
|
# Calculates how many characters are left for the next segment.
|
|
179
235
|
#
|
|
180
236
|
# @param limit [Integer] total truncation limit.
|
data/lib/meta_tags/version.rb
CHANGED
data/lib/meta_tags.rb
CHANGED
|
@@ -2,7 +2,7 @@ module MetaTags
|
|
|
2
2
|
class Configuration
|
|
3
3
|
type html_tag_key = String | Symbol
|
|
4
4
|
type html_tag_value = Hash[html_tag_key, html_tag_value] | Array[html_tag_value] | html_tag_content
|
|
5
|
-
type html_tag_content = String? | Symbol | Numeric | bool | (_Stringish & Object)
|
|
5
|
+
type html_tag_content = String? | Symbol | Numeric | bool | (_Stringish & Object) | (_Timish & Object)
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
attr_accessor title_limit: Integer?
|
|
@@ -11,7 +11,7 @@ module MetaTags
|
|
|
11
11
|
attr_accessor truncate_array_items_at_boundaries: bool
|
|
12
12
|
attr_accessor title_tag_attributes: Hash[html_tag_key, html_tag_value]?
|
|
13
13
|
attr_accessor description_limit: Integer?
|
|
14
|
-
attr_accessor keywords_limit: Integer
|
|
14
|
+
attr_accessor keywords_limit: Integer?
|
|
15
15
|
attr_accessor keywords_separator: String
|
|
16
16
|
attr_accessor keywords_lowercase: bool
|
|
17
17
|
attr_accessor open_meta_tags: bool
|
|
@@ -7,8 +7,14 @@ module MetaTags
|
|
|
7
7
|
|
|
8
8
|
def render: (*untyped args) ?{ () -> untyped } -> untyped
|
|
9
9
|
|
|
10
|
+
def render_to_string: (*untyped args) ?{ () -> untyped } -> untyped
|
|
11
|
+
|
|
10
12
|
def set_meta_tags: (meta_tags | (_MetaTagish & Object) meta_tags) -> void
|
|
11
13
|
|
|
12
14
|
def meta_tags: () -> MetaTagsCollection
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def set_meta_tags_from_instance_variables: () -> void
|
|
13
19
|
end
|
|
14
20
|
end
|
data/sig/lib/meta_tags/tag.rbs
CHANGED
|
@@ -7,6 +7,8 @@ module MetaTags
|
|
|
7
7
|
|
|
8
8
|
def render: (_ActionViewBase view) -> String
|
|
9
9
|
|
|
10
|
+
def drop_blank_attribute_names: (Hash[String | Symbol, untyped] attributes) -> Hash[String | Symbol, untyped]
|
|
11
|
+
|
|
10
12
|
def serialize_iso8601_attributes: (Hash[String | Symbol, untyped] attributes) -> Hash[String | Symbol, untyped]
|
|
11
13
|
end
|
|
12
14
|
end
|
|
@@ -5,7 +5,7 @@ module MetaTags
|
|
|
5
5
|
type keyword = String? | (_Stringish & Object)
|
|
6
6
|
type keywords = keyword | Array[keywords]
|
|
7
7
|
|
|
8
|
-
def normalize_title: (String? site_title, keywords title, String separator, ?bool
|
|
8
|
+
def normalize_title: (String? site_title, keywords title, String separator, ?reverse: bool, ?lowercase: bool) -> String
|
|
9
9
|
|
|
10
10
|
def normalize_description: (keyword description) -> String
|
|
11
11
|
|
|
@@ -17,16 +17,19 @@ module MetaTags
|
|
|
17
17
|
|
|
18
18
|
def safe_join: (Array[String] array, ?String sep) -> String
|
|
19
19
|
|
|
20
|
-
def cleanup_string: (keyword string, ?strip: bool strip) -> String
|
|
20
|
+
def cleanup_string: (keyword string, ?strip: bool strip, ?limit: Integer? limit) -> String
|
|
21
21
|
|
|
22
|
-
def cleanup_strings: (keywords? strings, ?strip: bool strip) -> Array[String]
|
|
22
|
+
def cleanup_strings: (keywords? strings, ?strip: bool strip, ?limit: Integer? limit) -> Array[String]
|
|
23
23
|
|
|
24
24
|
def truncate: (String string, ?Integer? limit) -> String
|
|
25
25
|
|
|
26
26
|
def truncate_array: (Array[String] string_array, ?Integer? limit, ?String separator) -> Array[String]
|
|
27
|
+
| (Enumerable[String] string_array, ?Integer? limit, ?String separator) -> Enumerable[String]
|
|
27
28
|
|
|
28
29
|
private
|
|
29
30
|
|
|
31
|
+
def truncate_markup: (String string, Integer? limit) -> String
|
|
32
|
+
|
|
30
33
|
def calculate_limit_left: (Integer limit, Integer length, Array[String] result, String separator) -> untyped
|
|
31
34
|
|
|
32
35
|
def truncate_title: (String site_title, Array[String] title, String separator) -> ::Array[untyped]
|
|
@@ -10,7 +10,7 @@ module MetaTags
|
|
|
10
10
|
|
|
11
11
|
def set_meta_tags: (?meta_tags | (_MetaTagish & Object) meta_tags) -> void
|
|
12
12
|
|
|
13
|
-
def title: (?(stringish | Array[stringish]) title, ?::String? headline) -> String
|
|
13
|
+
def title: (?(stringish | Array[stringish] | nil) title, ?::String? headline) -> String
|
|
14
14
|
|
|
15
15
|
def keywords: (TextNormalizer::keywords keywords) -> TextNormalizer::keywords
|
|
16
16
|
|
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: meta-tags
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.25.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dmytro Shteflyuk
|
|
@@ -12,7 +12,7 @@ cert_chain:
|
|
|
12
12
|
-----BEGIN CERTIFICATE-----
|
|
13
13
|
MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQsFADA/MQ8wDQYDVQQDDAZrcHVt
|
|
14
14
|
dWsxFjAUBgoJkiaJk/IsZAEZFgZrcHVtdWsxFDASBgoJkiaJk/IsZAEZFgRpbmZv
|
|
15
|
-
|
|
15
|
+
MB4XDTI2MTEyODE0MzU1MloXDTI3MTEyODE0MzU1MlowPzEPMA0GA1UEAwwGa3B1
|
|
16
16
|
bXVrMRYwFAYKCZImiZPyLGQBGRYGa3B1bXVrMRQwEgYKCZImiZPyLGQBGRYEaW5m
|
|
17
17
|
bzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALw2YroZc+IT+rs8NuPu
|
|
18
18
|
c13DelrxrpAgPEu1zuRb3l7WaHRNWA4TyS8Z6Aa1G2O+FdUZNMW1n7IwP/QMJ9Mz
|
|
@@ -23,14 +23,14 @@ cert_chain:
|
|
|
23
23
|
/1sCAwEAAaN3MHUwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFPa4
|
|
24
24
|
VFc1YOlV1u/7EGTwMCAk8YE9MB0GA1UdEQQWMBSBEmtwdW11a0BrcHVtdWsuaW5m
|
|
25
25
|
bzAdBgNVHRIEFjAUgRJrcHVtdWtAa3B1bXVrLmluZm8wDQYJKoZIhvcNAQELBQAD
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
ggEBAGSpWh2R8DV3hZgcukoPFrCVnRAHHYeQz0BhB7c/it2pITgy6F76HFcJLvHg
|
|
27
|
+
OoLg0EeOyc/ClcBN8DCl+ZkHVkqEy6FXiURDQyTprsNbrYfaDcy8kaHJZwhgC9Xq
|
|
28
|
+
Osv/1yVtXOP6L4C42TzrI02zFquFmdKYqsi3KU/dEOiyTS9mktDE3Ha7PLq9lIB8
|
|
29
|
+
13+QKCjpJUMGlZ1jv8Bi9FkvneDdiH9ACt0T0/q8gh3RW3y0M/4RBD2lIFzbsGns
|
|
30
|
+
yrtanYI2gZSjOVJob8j8cnfTbptGf1KRwp6r6xYNAP4vjY5/6UbcY03lHjluHGqB
|
|
31
|
+
OFHUoH7OjqY3Uh5+KobrRnn9QMY=
|
|
32
32
|
-----END CERTIFICATE-----
|
|
33
|
-
date: 2026-
|
|
33
|
+
date: 2026-11-29 00:00:00.000000000 Z
|
|
34
34
|
dependencies:
|
|
35
35
|
- !ruby/object:Gem::Dependency
|
|
36
36
|
name: actionpack
|
|
@@ -38,14 +38,14 @@ dependencies:
|
|
|
38
38
|
requirements:
|
|
39
39
|
- - ">="
|
|
40
40
|
- !ruby/object:Gem::Version
|
|
41
|
-
version: 6.
|
|
41
|
+
version: 6.1.0
|
|
42
42
|
type: :runtime
|
|
43
43
|
prerelease: false
|
|
44
44
|
version_requirements: !ruby/object:Gem::Requirement
|
|
45
45
|
requirements:
|
|
46
46
|
- - ">="
|
|
47
47
|
- !ruby/object:Gem::Version
|
|
48
|
-
version: 6.
|
|
48
|
+
version: 6.1.0
|
|
49
49
|
- !ruby/object:Gem::Dependency
|
|
50
50
|
name: appraisal
|
|
51
51
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -66,14 +66,14 @@ dependencies:
|
|
|
66
66
|
requirements:
|
|
67
67
|
- - ">="
|
|
68
68
|
- !ruby/object:Gem::Version
|
|
69
|
-
version:
|
|
69
|
+
version: 6.1.0
|
|
70
70
|
type: :development
|
|
71
71
|
prerelease: false
|
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
|
73
73
|
requirements:
|
|
74
74
|
- - ">="
|
|
75
75
|
- !ruby/object:Gem::Version
|
|
76
|
-
version:
|
|
76
|
+
version: 6.1.0
|
|
77
77
|
- !ruby/object:Gem::Dependency
|
|
78
78
|
name: rake
|
|
79
79
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -122,28 +122,28 @@ dependencies:
|
|
|
122
122
|
requirements:
|
|
123
123
|
- - "~>"
|
|
124
124
|
- !ruby/object:Gem::Version
|
|
125
|
-
version: 0.
|
|
125
|
+
version: 1.0.1
|
|
126
126
|
type: :development
|
|
127
127
|
prerelease: false
|
|
128
128
|
version_requirements: !ruby/object:Gem::Requirement
|
|
129
129
|
requirements:
|
|
130
130
|
- - "~>"
|
|
131
131
|
- !ruby/object:Gem::Version
|
|
132
|
-
version: 0.
|
|
132
|
+
version: 1.0.1
|
|
133
133
|
- !ruby/object:Gem::Dependency
|
|
134
134
|
name: steep
|
|
135
135
|
requirement: !ruby/object:Gem::Requirement
|
|
136
136
|
requirements:
|
|
137
137
|
- - "~>"
|
|
138
138
|
- !ruby/object:Gem::Version
|
|
139
|
-
version:
|
|
139
|
+
version: 2.0.0
|
|
140
140
|
type: :development
|
|
141
141
|
prerelease: false
|
|
142
142
|
version_requirements: !ruby/object:Gem::Requirement
|
|
143
143
|
requirements:
|
|
144
144
|
- - "~>"
|
|
145
145
|
- !ruby/object:Gem::Version
|
|
146
|
-
version:
|
|
146
|
+
version: 2.0.0
|
|
147
147
|
- !ruby/object:Gem::Dependency
|
|
148
148
|
name: rubocop-rake
|
|
149
149
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -222,6 +222,7 @@ executables: []
|
|
|
222
222
|
extensions: []
|
|
223
223
|
extra_rdoc_files: []
|
|
224
224
|
files:
|
|
225
|
+
- AGENTS.md
|
|
225
226
|
- CHANGELOG.md
|
|
226
227
|
- CODE_OF_CONDUCT.md
|
|
227
228
|
- CONTRIBUTING.md
|
|
@@ -273,7 +274,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
273
274
|
requirements:
|
|
274
275
|
- - ">="
|
|
275
276
|
- !ruby/object:Gem::Version
|
|
276
|
-
version: 3.
|
|
277
|
+
version: 3.2.0
|
|
277
278
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
278
279
|
requirements:
|
|
279
280
|
- - ">="
|
metadata.gz.sig
CHANGED
|
Binary file
|