repost 0.3.3 → 0.3.8

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: 998c57594b27cb1c140eb6e141b2e64467a5cde407410c58bd3547f3529e7d20
4
- data.tar.gz: d7fef86b10e728d49154e6883fdf53659bbbacd0f281283e6ff586f82cc67199
3
+ metadata.gz: a14ab972e2dc07c9812af6c4faaa53a800f747fc2ea10d0270ef77a5860f9947
4
+ data.tar.gz: c27f117e61525fcdd16c9b7ca3fee667ce5740ab0a4407ea7106a608684bd341
5
5
  SHA512:
6
- metadata.gz: 4ce51773149c3bb5afc481c415753a46e2136d2ef1e41aa17709028ec24682c95a44a913dddba3ea20c06a15bb201384478ab6cac42cb1f41eba97316d35e875
7
- data.tar.gz: 97a6ab774d780fbe9cf238ee6172764adbc10d6dd6b0282f3c8950e967f413b560cb4852179d419c27d62dc1dd5ee542c66108864d90444902388a8c8235af64
6
+ metadata.gz: d354a54440a8089075e919b9a8f4f15f1f17a4f849dffd91602561e6d2ea8d393e0eb503bdb6fd1eda353e3b8f3d704e852020c5aaca2f6e91b4596301280a72
7
+ data.tar.gz: dfce38fbd72e5d8fd8d2896767cfa257721b33c4fdeeefdbcaba73a68dd6d5193dae91a8a26e45cbd7993fc6fcc01d4bfb7fd2b5549068130b965c625cb2899e
data/lib/repost/action.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Repost
2
2
  class Action
3
- def self.perform(*args)
4
- action = new(*args)
3
+ def self.perform(*args, **kw_args)
4
+ action = new(*args, **kw_args)
5
5
  action.perform
6
6
  end
7
7
  end
@@ -3,12 +3,16 @@ if defined?(Rails) && defined?(ActiveSupport)
3
3
  class ::ActionController::Base
4
4
 
5
5
  def repost(url, params: {}, options: {})
6
+ status = options.delete(:status) || :ok
6
7
  authenticity_token = form_authenticity_token if ['auto', :auto].include?(options[:authenticity_token])
7
8
  render html: Repost::Senpai.perform(
8
9
  url,
9
10
  params: params,
10
- options: options.merge({authenticity_token: authenticity_token}.compact)
11
- ).html_safe
11
+ options: options.merge({
12
+ authenticity_token: authenticity_token,
13
+ autosubmit_nonce: content_security_policy_nonce,
14
+ }.compact)
15
+ ).html_safe, status: status
12
16
  end
13
17
 
14
18
  alias :redirect_post :repost
data/lib/repost/senpai.rb CHANGED
@@ -12,6 +12,7 @@ module Repost
12
12
  @charset = options.fetch(:charset, DEFAULT_CHARSET)
13
13
  @form_id = options.fetch(:form_id, generated_form_id)
14
14
  @autosubmit = options.fetch(:autosubmit, true)
15
+ @autosubmit_nonce = options.fetch(:autosubmit_nonce, nil)
15
16
  @section_classes = options.dig(:decor, :section, :classes)
16
17
  @section_html = options.dig(:decor, :section, :html)
17
18
  @submit_classes = options.dig(:decor, :submit, :classes)
@@ -31,7 +32,7 @@ module Repost
31
32
 
32
33
  attr_reader :url, :params, :options, :method, :form_id, :autosubmit,
33
34
  :section_classes, :section_html, :submit_classes,
34
- :submit_text, :authenticity_token, :charset
35
+ :submit_text, :authenticity_token, :charset, :autosubmit_nonce
35
36
 
36
37
  def form_head
37
38
  "<form id='#{form_id}' action='#{url}' method='#{method}' accept-charset='#{charset}'>"
@@ -46,12 +47,17 @@ module Repost
46
47
  end
47
48
 
48
49
  def form_input(key, value)
49
- if value.is_a?(Hash)
50
+ case value
51
+ when Hash
50
52
  value.map do |inner_key, inner_value|
51
53
  form_input("#{key}[#{inner_key}]", inner_value)
52
54
  end.join
55
+ when Array
56
+ value.map do |inner_value|
57
+ form_input("#{key}[]", inner_value)
58
+ end.join
53
59
  else
54
- "<input type='hidden' name='#{key}' value='#{value}'>"
60
+ "<input type='hidden' name='#{key}' value=#{process_value(value)}>"
55
61
  end
56
62
  end
57
63
 
@@ -81,9 +87,15 @@ module Repost
81
87
  end
82
88
 
83
89
  def auto_submit_script
84
- "<script>
90
+ nonce_attr = %Q( nonce="#{autosubmit_nonce}") if autosubmit_nonce
91
+ "<script#{nonce_attr}>
85
92
  document.getElementById('#{form_id}').submit();
86
93
  </script>"
87
94
  end
95
+
96
+ def process_value(value)
97
+ return value if value.is_a?(Integer)
98
+ '\'' + value.to_s + '\''
99
+ end
88
100
  end
89
101
  end
@@ -1,3 +1,3 @@
1
1
  module Repost
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: repost
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - YaroslavO
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-17 00:00:00.000000000 Z
11
+ date: 2021-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler