haml 7.3.1 → 7.4.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: edacb8b933c632df2c2f0beed8d95db7070ab5fe453e3591be2667337fa771cd
4
- data.tar.gz: ad9334257bb8ee5979b6a5d72e88923305ee96cd80769e1dfcb4d57e0a393c88
3
+ metadata.gz: 6a5bc7150b467bde9b4effce4bdc2b568a0b6a5644d7254b69a9de6ea6c807af
4
+ data.tar.gz: 172ab49b7e798cb37dd97ebfa037d27bd53dd5f8924f7111d9ac23c1de13d1ba
5
5
  SHA512:
6
- metadata.gz: f1f5118de9705e5b1ea4903a2bcd774d4086ff9dbbe0e7f39c11882d966be3f7c4d9cf29969613420615d6df64a375d41e4f1142d8141a85855eed2050bee908
7
- data.tar.gz: 982e894cce3e305b1c7b7448efd3455a59ebbcf7856821abccf0a548674e5923760c885d6ef2dbf6e324fa69aae73d311a4cb8331a25f94afce4e6e6986d2c8d
6
+ metadata.gz: 4950862786ea326cfe7df4276bd75c99ce9e00cea7f9446b568880bb7a2999ad0b3dec92b4e0b0bfbd6b9b725a847f00ae6ff9f29ce1f0573efdf9ee0a283b91
7
+ data.tar.gz: 5ec5253e40f7dfd02fb4e6b537fe2c929590356d1e5130abe211c522e2d0856b7ceaaa1c951d8e7fa672bb4289f7a8284f3e3d384e6eec31552525546e31432a
data/CHANGELOG.md CHANGED
@@ -1,8 +1,16 @@
1
1
  # Haml Changelog
2
2
 
3
+ ## 7.4.0
4
+
5
+ * `Haml::BOOLEAN_ATTRIBUTES` is changed from Array to Set https://github.com/haml/haml/pull/1216
6
+ * A guard on `respond_to?(:html_safe?)` is removed from `Haml::Util.escape_html_safe` https://github.com/haml/haml/pull/1217
7
+ * Keep interpolated text in the source encoding, fixing the `Encoding::CompatibilityError` remaining on an ASCII-8BIT
8
+ template source that mixes plain text and interpolation with non-ASCII characters https://github.com/haml/haml/issues/1218
9
+
3
10
  ## 7.3.1
4
11
 
5
- * Keep Prism-derived fragments in the source encoding, fixing `Encoding::CompatibilityError` on an ASCII-8BIT template source with non-ASCII characters (regression in 7.3.0) https://github.com/haml/haml/issues/1218
12
+ * Keep Prism-derived fragments in the source encoding, fixing `Encoding::CompatibilityError` on an ASCII-8BIT
13
+ template source with non-ASCII characters (regression in 7.3.0) https://github.com/haml/haml/issues/1218
6
14
 
7
15
  ## 7.3.0
8
16
 
data/REFERENCE.md CHANGED
@@ -320,7 +320,7 @@ or using `true` and `false`:
320
320
  %input(selected=true)
321
321
 
322
322
  This feature works only for attributes that are included in
323
- [`Haml::BOOLEAN_ATTRIBUTES`](https://github.com/haml/haml/blob/main/lib/haml/attribute_compiler.rb#L8),
323
+ [`Haml::BOOLEAN_ATTRIBUTES`](https://github.com/haml/haml/blob/main/lib/haml/attribute_compiler.rb#L9),
324
324
  as well as `data-` and `aria-` attributes.
325
325
 
326
326
  %input{'data-hidden' => false}
@@ -19,10 +19,12 @@ module Haml::AttributeBuilder
19
19
  buf << build_data(escape_attrs, quote, format, *hash[key])
20
20
  when 'aria'
21
21
  buf << build_aria(escape_attrs, quote, format, *hash[key])
22
- when *Haml::BOOLEAN_ATTRIBUTES, /\Adata-/, /\Aaria-/
23
- build_boolean!(escape_attrs, quote, format, buf, key, hash[key])
24
22
  else
25
- buf << " #{key}=#{quote}#{escape_html(escape_attrs, hash[key].to_s)}#{quote}"
23
+ if boolean_attribute?(key)
24
+ build_boolean!(escape_attrs, quote, format, buf, key, hash[key])
25
+ else
26
+ buf << " #{key}=#{quote}#{escape_html(escape_attrs, hash[key].to_s)}#{quote}"
27
+ end
26
28
  end
27
29
  end
28
30
  buf.join
@@ -72,6 +74,10 @@ module Haml::AttributeBuilder
72
74
 
73
75
  private
74
76
 
77
+ def boolean_attribute?(key)
78
+ Haml::BOOLEAN_ATTRIBUTES.include?(key) || key.start_with?('data-', 'aria-')
79
+ end
80
+
75
81
  def build_data_attribute(key, escape_attrs, quote, format, *hashes)
76
82
  attrs = []
77
83
  if hashes.size > 1 && hashes.all? { |h| h.is_a?(Hash) }
@@ -98,14 +104,18 @@ module Haml::AttributeBuilder
98
104
  flattened = {}
99
105
 
100
106
  attributes.each do |key, value|
107
+ # Recursing into a hash which contains itself would never end.
108
+ next if value.equal?(attributes)
109
+
101
110
  case value
102
- when attributes
103
111
  when Hash
104
112
  flatten_attributes(value).each do |k, v|
105
113
  if k.nil?
106
114
  flattened[key] = v
107
115
  else
108
- flattened["#{key}-#{k.to_s.tr('_', '-')}"] = v
116
+ k = k.is_a?(Symbol) ? k.name : k.to_s
117
+ k = k.tr('_', '-') if k.include?('_')
118
+ flattened["#{key}-#{k}"] = v
109
119
  end
110
120
  end
111
121
  else
@@ -122,7 +132,8 @@ module Haml::AttributeBuilder
122
132
  raise ArgumentError, "Non-hash object is given to attributes!"
123
133
  end
124
134
  hash.each do |key, value|
125
- key = key.to_s
135
+ # Symbol#name hands back the interned String; to_s allocates one per render.
136
+ key = key.is_a?(Symbol) ? key.name : key.to_s
126
137
  case key
127
138
  when 'id', 'class', 'data', 'aria'
128
139
  merged[key] ||= []
@@ -1,16 +1,17 @@
1
1
  # frozen_string_literal: true
2
+ require 'set'
2
3
  require 'haml/attribute_builder'
3
4
  require 'haml/attribute_parser'
4
5
  require 'haml/ruby_expression'
5
6
 
6
7
  module Haml
7
- # The list of boolean attributes. You may add custom attributes to this constant.
8
- BOOLEAN_ATTRIBUTES = %w[disabled readonly multiple checked autobuffer
8
+ # The set of boolean attributes. You may add custom attributes to this constant.
9
+ BOOLEAN_ATTRIBUTES = Set.new(%w[disabled readonly multiple checked autobuffer
9
10
  autoplay controls loop selected hidden scoped async
10
11
  defer reversed ismap seamless muted required
11
12
  autofocus novalidate formnovalidate open pubdate
12
13
  itemscope allowfullscreen default inert sortable
13
- truespeed typemustmatch download]
14
+ truespeed typemustmatch download])
14
15
 
15
16
  class AttributeCompiler
16
17
  def initialize(identity, options)
@@ -55,10 +56,12 @@ module Haml
55
56
  compile_class!(temple, key, values)
56
57
  when 'data', 'aria'
57
58
  compile_data!(temple, key, values)
58
- when *BOOLEAN_ATTRIBUTES, /\Adata-/, /\Aaria-/
59
- compile_boolean!(temple, key, values)
60
59
  else
61
- compile_common!(temple, key, values)
60
+ if BOOLEAN_ATTRIBUTES.include?(key) || key.start_with?('data-', 'aria-')
61
+ compile_boolean!(temple, key, values)
62
+ else
63
+ compile_common!(temple, key, values)
64
+ end
62
65
  end
63
66
  end
64
67
  temple
data/lib/haml/parser.rb CHANGED
@@ -444,7 +444,8 @@ module Haml
444
444
  end
445
445
  else
446
446
  if Util.contains_interpolation?(value)
447
- value = Util.unescape_interpolation(value, escape_html)
447
+ value = Util.unescape_interpolation(value)
448
+ escape_interpolation = true if escape_html
448
449
  parse = true
449
450
  escape_html = false
450
451
  end
data/lib/haml/util.rb CHANGED
@@ -26,10 +26,9 @@ module Haml
26
26
  end
27
27
  end
28
28
 
29
- # TODO: Remove unescape_interpolation's workaround and get rid of `respond_to?`.
30
29
  def self.escape_html_safe(html)
31
30
  html = html.to_s
32
- (html.respond_to?(:html_safe?) && html.html_safe?) ? html : escape_html(html)
31
+ html.html_safe? ? html : escape_html(html)
33
32
  end
34
33
 
35
34
  # Silence all output to STDERR within a block.
@@ -202,7 +201,7 @@ MSG
202
201
  /#[\{$@]/ === str
203
202
  end
204
203
 
205
- def unescape_interpolation(str, escape_html = nil)
204
+ def unescape_interpolation(str)
206
205
  res = ''.dup
207
206
  rest = Haml::Util.handle_interpolation str.dump do |scan|
208
207
  escapes = (scan[2].size - 1) / 2
@@ -218,12 +217,17 @@ MSG
218
217
  end
219
218
  content = eval("\"#{interpolated}\"")
220
219
  content = "#{char}#{content}" if char == '@' || char == '$'
221
- content = "Haml::Util.escape_html_safe((#{content}).to_s)" if escape_html
222
220
 
223
221
  res << "\#{#{content}}"
224
222
  end
225
223
  end
226
- res + rest
224
+ # The result is rebuilt from `str.dump` fragments and eval'd pieces, so it can
225
+ # come out tagged with an encoding that differs from `str`'s (e.g. UTF-8 for a
226
+ # BINARY source). The compiled template joins this string literal's fragments
227
+ # with fragments sliced out of the source itself, and mixed encodings raise
228
+ # Encoding::CompatibilityError, so bring it back to the source encoding.
229
+ # See haml/haml#1218.
230
+ (res + rest).force_encoding(str.encoding)
227
231
  end
228
232
 
229
233
  private
data/lib/haml/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Haml
3
- VERSION = '7.3.1'
3
+ VERSION = '7.4.0'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.3.1
4
+ version: 7.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Natalie Weizenbaum