unpoly-rails 3.3.0 → 3.3.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 614551454d692e572ca5c9a0a231ad5b8b94e916a04665e0644a624ce20844a8
4
- data.tar.gz: b9f1cf1029a6330314c49378a417da6f802630a8e2b9be7a6bc98c1bbcfdc0e5
3
+ metadata.gz: d6168b30ebc03dcb29e92bf01cf3641f450b73c77caf36524583fa285c36e7aa
4
+ data.tar.gz: dbe8e882e7875489d750a5477ff731941360ae7f8c9e418c728a6893948dc23a
5
5
  SHA512:
6
- metadata.gz: 957eb63eee7f194196b454c0321eb1052f71582762378cd3190d94f9017885af6f035ab8622bc9df83b84a05793544614b1643486ca1e0f1d344ef1fdf3590ad
7
- data.tar.gz: 8ece3837631ec7cc14394996dba8c803bd49c73c25f9729ddf81a01e9ddfd4989e1a900435cad179157d115351cc6e24ac8c1f7f7a64b1d6ebaf3044b8088444
6
+ metadata.gz: 29567f4fdb9668df6cba8e4fab7a758dd640395490b39d67ee4187f8474e0ecc4f6c0b36ccda8cf5f54479a642dcb7d30be71b4baeef02d5bf87145fc4ee44f2
7
+ data.tar.gz: b3f432523d96491a4d0c9908457134999ecfc400c0d26de04ee5ef6105b93a1fb453c44ad4f271f3f22ceb0c654053b46f8107dad0f0d06e10b461ee81b841e7
@@ -48,7 +48,7 @@ module Unpoly
48
48
  end
49
49
 
50
50
  ##
51
- # An array of strings, serialized as JSON.
51
+ # An array of strings, separated by a space character.
52
52
  class SeparatedValues < Field
53
53
 
54
54
  def initialize(name, separator: ' ', default: nil)
@@ -60,8 +60,8 @@ module Unpoly
60
60
  def parse(raw)
61
61
  if raw
62
62
  raw.split(@separator)
63
- elsif @default
64
- instance_exec(&@default)
63
+ else
64
+ @default&.call
65
65
  end
66
66
  end
67
67
 
@@ -101,11 +101,7 @@ module Unpoly
101
101
  end
102
102
 
103
103
  def parse(raw)
104
- if raw.present?
105
- result = Util.json_decode(raw)
106
- elsif @default
107
- result = instance_exec(&@default)
108
- end
104
+ result = Util.guard_json_decode(raw, &@default)
109
105
 
110
106
  if result.is_a?(::Hash)
111
107
  result = ActiveSupport::HashWithIndifferentAccess.new(result)
@@ -132,13 +128,7 @@ module Unpoly
132
128
  end
133
129
 
134
130
  def parse(raw)
135
- if raw.present?
136
- result = Util.json_decode(raw)
137
- elsif @default
138
- result = instance_exec(&@default)
139
- end
140
-
141
- result
131
+ Util.guard_json_decode(raw, &@default)
142
132
  end
143
133
 
144
134
  def stringify(value)
@@ -3,8 +3,20 @@ module Unpoly
3
3
  class Util
4
4
  class << self
5
5
 
6
- def json_decode(string)
7
- ActiveSupport::JSON.decode(string)
6
+ def guard_json_decode(raw, &default)
7
+ if raw.present?
8
+ begin
9
+ ActiveSupport::JSON.decode(raw)
10
+ rescue ActiveSupport::JSON.parse_error
11
+ # We would love to crash here, as it might indicate a bug in the frontend code.
12
+ # Unfortunately security scanners may be spamming malformed JSON in X-Up headers,
13
+ # DOSing us with error notifications.
14
+ ::Rails.logger.error('unpoly-rails: Ignoring malformed JSON in X-Up header')
15
+ default&.call
16
+ end
17
+ else
18
+ default&.call
19
+ end
8
20
  end
9
21
 
10
22
  # We build a lot of JSON that goes into HTTP header.
@@ -2,8 +2,7 @@ module Unpoly
2
2
  module Rails
3
3
  ##
4
4
  # The current version of the unpoly-rails gem.
5
- # This version number is also used for releases of the Unpoly
6
- # frontend code.
7
- VERSION = '3.3.0'
5
+ # The first 3 digits should match the version of the Unpoly frontend code.
6
+ VERSION = '3.3.0.1'
8
7
  end
9
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unpoly-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henning Koch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-16 00:00:00.000000000 Z
11
+ date: 2023-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties