haml 7.3.0 → 7.3.1

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: 381430279e5ca21c3d03f899c686f972609e54633c8e530609511e852597b7ef
4
- data.tar.gz: a108268dccda6dc0e3ca014e484a7bcc0f50c973771a0057a086d75de2847495
3
+ metadata.gz: edacb8b933c632df2c2f0beed8d95db7070ab5fe453e3591be2667337fa771cd
4
+ data.tar.gz: ad9334257bb8ee5979b6a5d72e88923305ee96cd80769e1dfcb4d57e0a393c88
5
5
  SHA512:
6
- metadata.gz: b5f8d7bcc23e52be3fd4ed443ec3fdf171773f9c9aaacd1705d92ec09a3ef372adf13a8715ca4b4d039aa2a07fc2fdbb7e59eef30a22f55be2823bb0c7e23f0d
7
- data.tar.gz: 954f3aa91fa3f49499d05dd1503056dd65a439519c5b2bcc300a6cf3dfbacf686717c8aa1e10ddb1ca7fa779504d92561a33e8a7d729b8013967cde102636fca
6
+ metadata.gz: f1f5118de9705e5b1ea4903a2bcd774d4086ff9dbbe0e7f39c11882d966be3f7c4d9cf29969613420615d6df64a375d41e4f1142d8141a85855eed2050bee908
7
+ data.tar.gz: 982e894cce3e305b1c7b7448efd3455a59ebbcf7856821abccf0a548674e5923760c885d6ef2dbf6e324fa69aae73d311a4cb8331a25f94afce4e6e6986d2c8d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Haml Changelog
2
2
 
3
+ ## 7.3.1
4
+
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
6
+
3
7
  ## 7.3.0
4
8
 
5
9
  * Replace Ripper with Prism https://github.com/haml/haml/pull/1214
@@ -32,7 +32,7 @@ module Haml
32
32
  key = static_key(element.key)
33
33
  return if key.nil?
34
34
 
35
- hash[key] = value_source(element.value)
35
+ hash[in_source_encoding(key, exp)] = in_source_encoding(value_source(element.value), exp)
36
36
  end
37
37
  hash
38
38
  end
@@ -74,5 +74,15 @@ module Haml
74
74
 
75
75
  value.slice
76
76
  end
77
+
78
+ # Prism tags its slices with the encoding it parsed the source under (UTF-8 for a
79
+ # BINARY source), while the rest of the compiled template stays in the source
80
+ # encoding. Mixing the two raises Encoding::CompatibilityError once both sides hold
81
+ # non-ASCII bytes, so bring everything back to the source encoding.
82
+ def in_source_encoding(string, source)
83
+ return string if string.encoding == source.encoding
84
+
85
+ string.dup.force_encoding(source.encoding)
86
+ end
77
87
  end
78
88
  end
@@ -10,7 +10,7 @@ module Haml
10
10
  def compile(code, node: RubyExpression.string_literal_node(code))
11
11
  case node
12
12
  when Prism::StringNode
13
- node.unescaped.empty? ? [] : [[:static, node.unescaped]]
13
+ node.unescaped.empty? ? [] : [[:static, in_source_encoding(node.unescaped, code)]]
14
14
  when Prism::InterpolatedStringNode
15
15
  compile_parts(node.parts, code)
16
16
  else
@@ -33,12 +33,12 @@ module Haml
33
33
  case part
34
34
  when Prism::StringNode
35
35
  content = part.unescaped
36
- exps << [:static, content] unless content.empty?
36
+ exps << [:static, in_source_encoding(content, code)] unless content.empty?
37
37
  when Prism::EmbeddedStatementsNode
38
38
  embedded = embedded_source(part, code)
39
39
  exps << [:dynamic, embedded] unless embedded.empty?
40
40
  when Prism::EmbeddedVariableNode
41
- exps << [:dynamic, part.variable.slice]
41
+ exps << [:dynamic, in_source_encoding(part.variable.slice, code)]
42
42
  else
43
43
  # Prism allows more part types than a string literal can currently hold. Dropping
44
44
  # one would silently lose content, so fail instead of rendering something wrong.
@@ -54,6 +54,17 @@ module Haml
54
54
  from = part.opening_loc.end_offset
55
55
  code.byteslice(from, part.closing_loc.start_offset - from)
56
56
  end
57
+
58
+ # Prism tags what it returns with the encoding it parsed `code` under (UTF-8 for
59
+ # a BINARY source), while the fragments Haml slices out of the source itself keep
60
+ # the source encoding. The compiled template mixes both kinds, so anything taken
61
+ # from Prism has to come back to the source encoding, or joining the fragments
62
+ # raises Encoding::CompatibilityError once both sides hold non-ASCII bytes.
63
+ def in_source_encoding(string, code)
64
+ return string if string.encoding == code.encoding
65
+
66
+ string.dup.force_encoding(code.encoding)
67
+ end
57
68
  end
58
69
 
59
70
  def on_dynamic(code)
data/lib/haml/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Haml
3
- VERSION = '7.3.0'
3
+ VERSION = '7.3.1'
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.0
4
+ version: 7.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Natalie Weizenbaum