phlex 1.6.0 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of phlex might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eeac8033b47d1e0cf99832bc7a42a7777ca44643dd503f3cb08087666b08d4f7
4
- data.tar.gz: 6f7e786e982dcc9133c40179d4bb582d9d45bb610814020e916a2afbf17cb0d0
3
+ metadata.gz: 85f8d8d06e49280c1fd480bf596fd6f13e76d9872fe363349e9e481d8c32fe44
4
+ data.tar.gz: 55b77a7f744a657406a84f98cc049d38b3a4631dd60d29b45a0d33022efb7695
5
5
  SHA512:
6
- metadata.gz: 037caf900c1155b1e9095588a30dff67a7f224b6e16365d417dc7412e34822cb1368a194a4e48de65c20a838b91f671e7e53fca7a0f0e973852d84ebc7c03d3c
7
- data.tar.gz: 85ad16185650ff8aa04831c745ac6709ae35913863af0fef5a70d671d75dbbdf389005db6480cb5c4533ad9e3106379cb6aa2015b64194ca78a2dd8b61cd3993
6
+ metadata.gz: a1628997a70876299299b3825bfb9da74be95703d7402898f57e550945eb1b35da61382237914729ab1f90faeca671d377b10c28ae3c22589afb8f23b5a4d0f4
7
+ data.tar.gz: 0e62cb5507038341d2f4ef8104fbf6cc79723032cb5b88510c5d44376ba4668b44571a047819b0f03b900abdd6d0c8f8585c369d0f1923db9482962e95d91393
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.2.1
1
+ 3.3.0
@@ -3,11 +3,11 @@
3
3
  module Phlex
4
4
  module ElementClobberingGuard
5
5
  def method_added(method_name)
6
- if method_name[0] == "_" && private_instance_methods.include?(:"__phlex#{method_name}__")
6
+ if method_name[0] == "_" && element_method?(method_name[1..].to_sym)
7
7
  raise NameError, "👋 Redefining the method `#{name}##{method_name}` is not a good idea."
8
+ else
9
+ super
8
10
  end
9
-
10
- super
11
11
  end
12
12
  end
13
13
  end
@@ -5,45 +5,44 @@ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.0")
5
5
  end
6
6
 
7
7
  module Phlex::Elements
8
- private def slow_registered_elements
9
- private_instance_methods
10
- .lazy
11
- .map(&:to_s)
12
- .select { |m| m.start_with?("__phlex_") }
13
- .map { |m| m[8...-2].to_sym }
8
+ def registered_elements
9
+ @registered_elements ||= Concurrent::Map.new
14
10
  end
15
11
 
16
12
  def register_element(element, tag: element.name.tr("_", "-"))
17
13
  class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
18
14
  # frozen_string_literal: true
19
15
 
20
- def __phlex_#{element}__(**attributes, &block)
16
+
17
+ def #{element}(**attributes, &block)
18
+ target = @_context.target
19
+
21
20
  if attributes.length > 0 # with attributes
22
21
  if block_given? # with content block
23
- @_context.target << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[respond_to?(:process_attributes) ? (attributes.hash + self.class.hash) : attributes.hash] || __attributes__(**attributes)) << ">"
22
+ target << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[respond_to?(:process_attributes) ? (attributes.hash + self.class.hash) : attributes.hash] || __attributes__(**attributes)) << ">"
24
23
  yield_content(&block)
25
- @_context.target << "</#{tag}>"
24
+ target << "</#{tag}>"
26
25
  else # without content block
27
- @_context.target << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[respond_to?(:process_attributes) ? (attributes.hash + self.class.hash) : attributes.hash] || __attributes__(**attributes)) << "></#{tag}>"
26
+ target << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[respond_to?(:process_attributes) ? (attributes.hash + self.class.hash) : attributes.hash] || __attributes__(**attributes)) << "></#{tag}>"
28
27
  end
29
28
  else # without attributes
30
29
  if block_given? # with content block
31
- @_context.target << "<#{tag}>"
30
+ target << "<#{tag}>"
32
31
  yield_content(&block)
33
- @_context.target << "</#{tag}>"
32
+ target << "</#{tag}>"
34
33
  else # without content block
35
- @_context.target << "<#{tag}></#{tag}>"
34
+ target << "<#{tag}></#{tag}>"
36
35
  end
37
36
  end
38
37
 
39
38
  nil
40
39
  end
41
40
 
42
- alias_method :_#{element}, :__phlex_#{element}__
43
- alias_method :#{element}, :__phlex_#{element}__
44
- private :__phlex_#{element}__
41
+ alias_method :_#{element}, :#{element}
45
42
  RUBY
46
43
 
44
+ registered_elements[element] = tag
45
+
47
46
  element
48
47
  end
49
48
 
@@ -51,21 +50,23 @@ module Phlex::Elements
51
50
  class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
52
51
  # frozen_string_literal: true
53
52
 
54
- def __phlex_#{element}__(**attributes)
53
+ def #{element}(**attributes)
54
+ target = @_context.target
55
+
55
56
  if attributes.length > 0 # with attributes
56
- @_context.target << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[respond_to?(:process_attributes) ? (attributes.hash + self.class.hash) : attributes.hash] || __attributes__(**attributes)) << ">"
57
+ target << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[respond_to?(:process_attributes) ? (attributes.hash + self.class.hash) : attributes.hash] || __attributes__(**attributes)) << ">"
57
58
  else # without attributes
58
- @_context.target << "<#{tag}>"
59
+ target << "<#{tag}>"
59
60
  end
60
61
 
61
62
  nil
62
63
  end
63
64
 
64
- alias_method :_#{element}, :__phlex_#{element}__
65
- alias_method :#{element}, :__phlex_#{element}__
66
- private :__phlex_#{element}__
65
+ alias_method :_#{element}, :#{element}
67
66
  RUBY
68
67
 
68
+ registered_elements[element] = tag
69
+
69
70
  element
70
71
  end
71
72
  end
data/lib/phlex/sgml.rb CHANGED
@@ -12,8 +12,6 @@ module Phlex
12
12
  new(...).call
13
13
  end
14
14
 
15
- alias_method :render, :call
16
-
17
15
  # Create a new instance of the component.
18
16
  # @note The block will not be delegated to the initializer. Instead, it will be provided to `template` when rendering.
19
17
  def new(*args, **kwargs, &block)
@@ -31,6 +29,17 @@ module Phlex
31
29
  alias_method :__attributes__, :__final_attributes__
32
30
  alias_method :call, :__final_call__
33
31
  end
32
+
33
+ # @api private
34
+ def element_method?(method_name)
35
+ return false unless instance_methods.include?(method_name)
36
+
37
+ owner = instance_method(method_name).owner
38
+
39
+ return true if owner.is_a?(Phlex::Elements) && owner.registered_elements[method_name]
40
+
41
+ false
42
+ end
34
43
  end
35
44
 
36
45
  # Renders the view and returns the buffer. The default buffer is a mutable String.
@@ -52,7 +61,7 @@ module Phlex
52
61
 
53
62
  around_template do
54
63
  if block
55
- if DeferredRender === self
64
+ if is_a?(DeferredRender)
56
65
  __vanish__(self, &block)
57
66
  template
58
67
  else
@@ -118,11 +127,13 @@ module Phlex
118
127
  # Output a whitespace character. This is useful for getting inline elements to wrap. If you pass a block, a whitespace will be output before and after yielding the block.
119
128
  # @return [nil]
120
129
  def whitespace
121
- @_context.target << " "
130
+ target = @_context.target
131
+
132
+ target << " "
122
133
 
123
134
  if block_given?
124
135
  yield
125
- @_context.target << " "
136
+ target << " "
126
137
  end
127
138
 
128
139
  nil
@@ -131,9 +142,11 @@ module Phlex
131
142
  # Output an HTML comment.
132
143
  # @return [nil]
133
144
  def comment(&block)
134
- @_context.target << "<!-- "
145
+ target = @_context.target
146
+
147
+ target << "<!-- "
135
148
  yield_content(&block)
136
- @_context.target << " -->"
149
+ target << " -->"
137
150
 
138
151
  nil
139
152
  end
@@ -210,10 +223,11 @@ module Phlex
210
223
  private def yield_content
211
224
  return unless block_given?
212
225
 
213
- original_length = @_context.target.length
214
- content = yield(self)
226
+ target = @_context.target
215
227
 
216
- plain(content) if original_length == @_context.target.length
228
+ original_length = target.length
229
+ content = yield(self)
230
+ plain(content) if original_length == target.length
217
231
 
218
232
  nil
219
233
  end
@@ -223,9 +237,11 @@ module Phlex
223
237
  private def yield_content_with_args(*args)
224
238
  return unless block_given?
225
239
 
226
- original_length = @_context.target.length
240
+ target = @_context.target
241
+
242
+ original_length = target.length
227
243
  content = yield(*args)
228
- plain(content) if original_length == @_context.target.length
244
+ plain(content) if original_length == target.length
229
245
 
230
246
  nil
231
247
  end
@@ -243,14 +259,6 @@ module Phlex
243
259
  attributes = process_attributes(**attributes)
244
260
  end
245
261
 
246
- if attributes[:href]&.start_with?(/\s*javascript:/)
247
- attributes.delete(:href)
248
- end
249
-
250
- if attributes["href"]&.start_with?(/\s*javascript:/)
251
- attributes.delete("href")
252
- end
253
-
254
262
  buffer = +""
255
263
  __build_attributes__(attributes, buffer: buffer)
256
264
 
@@ -268,8 +276,11 @@ module Phlex
268
276
  else k.to_s
269
277
  end
270
278
 
279
+ lower_name = name.downcase
280
+ next if lower_name == "href" && v.start_with?(/\s*javascript:/i)
281
+
271
282
  # Detect unsafe attribute names. Attribute names are considered unsafe if they match an event attribute or include unsafe characters.
272
- if HTML::EVENT_ATTRIBUTES[name] || name.match?(/[<>&"']/)
283
+ if HTML::EVENT_ATTRIBUTES[lower_name] || name.match?(/[<>&"']/)
273
284
  raise ArgumentError, "Unsafe attribute name detected: #{k}."
274
285
  end
275
286
 
data/lib/phlex/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Phlex
4
- VERSION = "1.6.0"
4
+ VERSION = "1.6.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phlex
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Drapper
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-08 00:00:00.000000000 Z
11
+ date: 2024-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  requirements: []
120
- rubygems_version: 3.4.6
120
+ rubygems_version: 3.5.6
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: A framework for building views in Ruby.