monkrb 0.22.2 → 0.23.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.
data/lib/monk/views.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require "erb"
2
- require "cgi/escape"
2
+ require "erb/escape"
3
3
 
4
4
  require_relative "freeze_hooks"
5
5
  require_relative "errors"
@@ -36,6 +36,9 @@ module Monk
36
36
 
37
37
  DEFAULT_ROOT = "views".freeze
38
38
 
39
+ # What every compiled template's buffer starts as a dup of.
40
+ EMPTY = Raw.new("").freeze
41
+
39
42
  class << self
40
43
  # Every reader here is a plain attr_reader over an ivar initialized
41
44
  # eagerly below, never `@x ||= ...`: a lazy reader *writes* on first
@@ -46,17 +49,27 @@ module Monk
46
49
 
47
50
  # Escapes unless the value is already Raw, and returns Raw either
48
51
  # way -- so an explicit `<%= h(x) %>` isn't escaped twice by the
49
- # implicit `h` the compiler wraps every `<%= %>` in.
50
- # CGI.escapeHTML, not ERB::Util.html_escape, though they produce
51
- # byte-identical output: ERB's is not flagged Ractor-safe, so a
52
- # worker calling it raises Ractor::UnsafeError ("ractor unsafe
53
- # method called from not main ractor"). Found by
52
+ # implicit escape the compiler wraps every `<%= %>` in.
53
+ # ERB::Escape.html_escape, not ERB::Util.html_escape, though they
54
+ # produce byte-identical output: ERB::Util's is not flagged
55
+ # Ractor-safe, so a worker calling it raises Ractor::UnsafeError
56
+ # ("ractor unsafe method called from not main ractor"). Found by
54
57
  # test/ractor_integration_test.rb, in a real worker, not by reading
55
- # either implementation.
58
+ # either implementation. ERB::Escape's is, and unlike
59
+ # CGI.escapeHTML it returns its argument when there's nothing to
60
+ # escape instead of a copy.
56
61
  def h(value)
57
62
  return value if value.is_a?(Raw)
58
63
 
59
- Raw.new(CGI.escapeHTML(value.to_s))
64
+ Raw.new(ERB::Escape.html_escape(value.to_s))
65
+ end
66
+
67
+ # The implicit escape around every `<%= %>` (ERB has already called
68
+ # #to_s): #h without the Raw wrapper, since the result is appended
69
+ # to the buffer and dropped. For text with nothing to escape, the
70
+ # common case, it allocates nothing.
71
+ def escape(value)
72
+ value.is_a?(Raw) ? value : ERB::Escape.html_escape(value)
60
73
  end
61
74
 
62
75
  def compile(name, source, path = "(erb)")
@@ -143,14 +156,16 @@ module Monk
143
156
 
144
157
  # `<%= %>` escapes by default -- a deliberate break from stock ERB,
145
158
  # where it doesn't. ERB::Compiler emits `insert_cmd((expr).to_s)`
146
- # for every insertion, so pointing insert_cmd at Views.h is the
147
- # whole implementation; `raw(x)` opts back out.
159
+ # for every insertion, so pointing insert_cmd at Views.escape is the
160
+ # whole implementation; `raw(x)` opts back out. The buffer is a Raw
161
+ # from the start (a dup of EMPTY), so the template returns it as is
162
+ # rather than copying it into one.
148
163
  def compiled_source(source)
149
164
  compiler = ERB::Compiler.new("-")
150
- compiler.pre_cmd = ["_erbout = +''"]
151
- compiler.post_cmd = ["Monk::Views::Raw.new(_erbout)"]
165
+ compiler.pre_cmd = ["_erbout = +Monk::Views::EMPTY"]
166
+ compiler.post_cmd = ["_erbout"]
152
167
  compiler.put_cmd = "_erbout.<<"
153
- compiler.insert_cmd = "_erbout.<< Monk::Views.h"
168
+ compiler.insert_cmd = "_erbout.<< Monk::Views.escape"
154
169
  script, encoding, = compiler.compile(source)
155
170
  # ERB::Compiler#compile scans the source as ASCII-8BIT (see its
156
171
  # own String#b) and hands that tag straight through to any code
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monkrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.2
4
+ version: 0.23.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matteo Folin
@@ -206,6 +206,7 @@ files:
206
206
  - lib/monk/generators/mail.rb
207
207
  - lib/monk/generators/postgres.rb
208
208
  - lib/monk/generators/redis.rb
209
+ - lib/monk/generators/storage.rb
209
210
  - lib/monk/generators/websocket.rb
210
211
  - lib/monk/jobs.rb
211
212
  - lib/monk/jobs/adapters/pg.rb
@@ -251,6 +252,19 @@ files:
251
252
  - lib/monk/persistence/pool.rb
252
253
  - lib/monk/settings.rb
253
254
  - lib/monk/state_ractor.rb
255
+ - lib/monk/storage.rb
256
+ - lib/monk/storage/backends/file.rb
257
+ - lib/monk/storage/backends/s3.rb
258
+ - lib/monk/storage/errors.rb
259
+ - lib/monk/storage/input.rb
260
+ - lib/monk/storage/key.rb
261
+ - lib/monk/storage/object.rb
262
+ - lib/monk/storage/routes.rb
263
+ - lib/monk/storage/sig_v4.rb
264
+ - lib/monk/storage/sniff.rb
265
+ - lib/monk/storage/token.rb
266
+ - lib/monk/storage/upload.rb
267
+ - lib/monk/storage/url.rb
254
268
  - lib/monk/templates/auth/agents.md
255
269
  - lib/monk/templates/auth/app/mailers/auth_mailer.rb
256
270
  - lib/monk/templates/auth/app/routes/auth.rb
@@ -334,6 +348,11 @@ files:
334
348
  - lib/monk/templates/redis/config/redis.rb
335
349
  - lib/monk/templates/redis/setup.md
336
350
  - lib/monk/templates/redis/test/redis_test.rb
351
+ - lib/monk/templates/storage/agents.md
352
+ - lib/monk/templates/storage/app/routes/storage.rb
353
+ - lib/monk/templates/storage/config/storage.rb
354
+ - lib/monk/templates/storage/setup.md
355
+ - lib/monk/templates/storage/test/storage_test.rb
337
356
  - lib/monk/templates/websocket/agents.md
338
357
  - lib/monk/templates/websocket/app/sockets/chat.rb
339
358
  - lib/monk/templates/websocket/bin/websocket_server