metamagic 3.1.1 → 3.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5339c62a7823d6648e9df00ece50ef96c63ae8e8
4
- data.tar.gz: 2d520fb7ef485717ff88f0a839ca39f010592a73
3
+ metadata.gz: 3785bc6edacf42b58b3da6a84e82067f9c740ac8
4
+ data.tar.gz: 45c1275787928af7cf48adbc35e4035c55d0558f
5
5
  SHA512:
6
- metadata.gz: 6c30629cae86fd8fbeaddfeca49d2ac19c05678541d9bfc75e3ed702cfbd9ca90ff4db26bbbeff3bef5e31d436aad198bd46f8bbbb9d5723322f22ef8c8fe50a
7
- data.tar.gz: 372ce9d3f776f2fea1dfc42bdee3e9fe85a65d645c4a54ddc4243d392dd1bb06c1b52b1b6aa804b1b1e98cecd679725ab7eaabb5b260a5801d844386615bb341
6
+ metadata.gz: 4b15f67940db99c9a8a637094df1d87f85ae088d7f8a9c613ec095f636b813d8137a70d535ada796518301c2d2d2a41c12fe38698f8761a4ac8d63056a53f36d
7
+ data.tar.gz: 8f4bb4af01686c7adce5374216ebb9322c62ea7d31696962c8b22b3bf76e304b4802f6d6fdd9fa87d77b09135692183a5adcaaa759c86ea735190653c135c1a9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## Version 3.1.2
4
+
5
+ * Add HTML safety handling.
6
+
3
7
  ## Version 3.1.1
4
8
 
5
9
  * Adds support for specifying templates on all tag types.
data/lib/metamagic/tag.rb CHANGED
@@ -31,13 +31,13 @@ module Metamagic
31
31
  when Symbol
32
32
  send(template)
33
33
  when String
34
- template.gsub(/:\w+/) do |key|
35
- send(key[1..-1])
36
- end
34
+ ERB::Util.html_escape(template).gsub(/:\w+/) do |key|
35
+ ERB::Util.html_escape(send(key[1..-1]))
36
+ end.html_safe
37
37
  else
38
38
  raise "Unknown template type #{template.class}."
39
39
  end
40
- end.flatten.compact.uniq
40
+ end.flatten.compact.uniq.map { |value| ERB::Util.html_escape(value) }
41
41
  end
42
42
 
43
43
  def ==(other)
@@ -2,7 +2,7 @@ module Metamagic
2
2
  class MetaTag < Tag
3
3
  def to_html
4
4
  return if interpolated_values.empty?
5
- tag(:meta, name: key, content: interpolated_values.join(", "))
5
+ tag(:meta, name: key, content: interpolated_values.join(", ").html_safe)
6
6
  end
7
7
 
8
8
  def sort_order
@@ -1,7 +1,7 @@
1
1
  module Metamagic
2
2
  class TitleTag < Tag
3
3
  def to_html
4
- content_tag(:title, interpolated_values.join(separator)) if interpolated_values.any?
4
+ content_tag(:title, interpolated_values.join(separator).html_safe) if interpolated_values.any?
5
5
  end
6
6
 
7
7
  def sort_order
@@ -1,3 +1,3 @@
1
1
  module Metamagic
2
- VERSION = "3.1.1"
2
+ VERSION = "3.1.2"
3
3
  end
@@ -76,4 +76,18 @@ class MetaTagTest < ActionView::TestCase
76
76
  assert_equal %{<meta content="added, keywords, default, from, layout" name="keywords" />},
77
77
  metamagic(keywords: [:keywords, "added", "default", "keywords", "from", "layout"])
78
78
  end
79
+
80
+ test "html safe keywords" do
81
+ keywords ["one", "two &rarr; test".html_safe, "three"]
82
+
83
+ assert_equal %{<meta content="one, two &rarr; test, three" name="keywords" />},
84
+ metamagic
85
+ end
86
+
87
+ test "html unsafe keywords" do
88
+ keywords ["one", "two &rarr; test", "three"]
89
+
90
+ assert_equal %{<meta content="one, two &amp;rarr; test, three" name="keywords" />},
91
+ metamagic
92
+ end
79
93
  end
@@ -51,6 +51,13 @@ class MetamagicTest < ActionView::TestCase
51
51
  metamagic
52
52
  end
53
53
 
54
+ test "not adding templates from views" do
55
+ title "This is a :nonexistent_key"
56
+
57
+ assert_equal %{<title>This is a :nonexistent_key</title>},
58
+ metamagic
59
+ end
60
+
54
61
  test "sorting tags" do
55
62
  twitter card: :summary
56
63
  og image: "http://test.com/image.png"
@@ -79,6 +79,48 @@ class TitleTagTest < ActionView::TestCase
79
79
  metamagic(site: "My Site", title: -> { meta_title_for(site, title) })
80
80
  end
81
81
 
82
+ test "html safe titles" do
83
+ title "My Site &rarr; Test".html_safe
84
+
85
+ assert_equal %{<title>My Site &rarr; Test</title>},
86
+ metamagic
87
+ end
88
+
89
+ test "html safe titles in template" do
90
+ title "Test &rarr; Test".html_safe
91
+
92
+ assert_equal %{<title>Test &rarr; Test - My Site</title>},
93
+ metamagic(title: ":title - :site", site: "My Site")
94
+ end
95
+
96
+ test "html unsafe titles" do
97
+ title "My Site &rarr; Test"
98
+
99
+ assert_equal %{<title>My Site &amp;rarr; Test</title>},
100
+ metamagic
101
+ end
102
+
103
+ test "html unsafe titles in template" do
104
+ title "Test &rarr; Test"
105
+
106
+ assert_equal %{<title>Test &amp;rarr; Test - My Site</title>},
107
+ metamagic(title: ":title - :site", site: "My Site")
108
+ end
109
+
110
+ test "html safe title template" do
111
+ title "Test Title"
112
+
113
+ assert_equal %{<title>Test Title &rarr; My Site</title>},
114
+ metamagic(title: ":title &rarr; :site".html_safe, site: "My Site")
115
+ end
116
+
117
+ test "html unsafe title template" do
118
+ title "Test Title"
119
+
120
+ assert_equal %{<title>Test Title &amp;rarr; My Site</title>},
121
+ metamagic(title: ":title &rarr; :site", site: "My Site")
122
+ end
123
+
82
124
  test "deprecated title_template option" do
83
125
  title "Test Title"
84
126
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metamagic
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lasse Bunk