unpoly-rails 2.7.1.1 → 2.7.2.1

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

Potentially problematic release.


This version of unpoly-rails might be problematic. Click here for more details.

@@ -50,7 +50,7 @@ module Unpoly
50
50
  end
51
51
 
52
52
  def stringify(value)
53
- value.to_json
53
+ Util.safe_json_encode(value)
54
54
  end
55
55
 
56
56
  end
@@ -75,7 +75,7 @@ module Unpoly
75
75
 
76
76
  def parse(raw)
77
77
  if raw.present?
78
- result = ActiveSupport::JSON.decode(raw)
78
+ result = Util.json_decode(raw)
79
79
  else
80
80
  result = {}
81
81
  end
@@ -88,7 +88,7 @@ module Unpoly
88
88
  end
89
89
 
90
90
  def stringify(value)
91
- ActiveSupport::JSON.encode(value)
91
+ Util.safe_json_encode(value)
92
92
  end
93
93
 
94
94
  end
@@ -97,7 +97,7 @@ module Unpoly
97
97
 
98
98
  def parse(raw)
99
99
  if raw.present?
100
- result = ActiveSupport::JSON.decode(raw)
100
+ result = Util.json_decode(raw)
101
101
  else
102
102
  result = []
103
103
  end
@@ -106,7 +106,7 @@ module Unpoly
106
106
  end
107
107
 
108
108
  def stringify(value)
109
- ActiveSupport::JSON.encode(value)
109
+ Util.safe_json_encode(value)
110
110
  end
111
111
 
112
112
  end
@@ -40,14 +40,14 @@ module Unpoly
40
40
  # TODO: Docs
41
41
  def accept(value = nil)
42
42
  overlay? or raise CannotClose, 'Cannot accept the root layer'
43
- change.response.headers['X-Up-Accept-Layer'] = value.to_json
43
+ change.response.headers['X-Up-Accept-Layer'] = Util.safe_json_encode(value)
44
44
  end
45
45
 
46
46
  ##
47
47
  # TODO: Docs
48
48
  def dismiss(value = nil)
49
49
  overlay? or raise CannotClose, 'Cannot dismiss the root layer'
50
- change.response.headers['X-Up-Dismiss-Layer'] = value.to_json
50
+ change.response.headers['X-Up-Dismiss-Layer'] = Util.safe_json_encode(value)
51
51
  end
52
52
 
53
53
  private
@@ -57,4 +57,4 @@ module Unpoly
57
57
  end
58
58
  end
59
59
  end
60
- end
60
+ end
@@ -0,0 +1,25 @@
1
+ module Unpoly
2
+ module Rails
3
+ class Util
4
+ class << self
5
+
6
+ def json_decode(string)
7
+ ActiveSupport::JSON.decode(string)
8
+ end
9
+
10
+ # We build a lot of JSON that goes into HTTP header.
11
+ # High-ascii characters are not safe to transport over HTTP, but we
12
+ # can use JSON escape sequences (\u0012) to make them low-ascii.
13
+ def safe_json_encode(value)
14
+ json = ActiveSupport::JSON.encode(value)
15
+ escape_non_ascii(json)
16
+ end
17
+
18
+ def escape_non_ascii(unicode_string)
19
+ unicode_string.gsub(/[[:^ascii:]]/) { |char| "\\u" + char.ord.to_s(16).rjust(4, "0") }
20
+ end
21
+
22
+ end
23
+ end
24
+ end
25
+ end
@@ -4,6 +4,6 @@ module Unpoly
4
4
  # The current version of the unpoly-rails gem.
5
5
  # This version number is also used for releases of the Unpoly
6
6
  # frontend code.
7
- VERSION = '2.7.1.1'
7
+ VERSION = '2.7.2.1'
8
8
  end
9
9
  end
data/lib/unpoly-rails.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'memoized'
2
2
  require_relative 'unpoly/rails/version'
3
3
  require_relative 'unpoly/rails/error'
4
+ require_relative 'unpoly/rails/util'
4
5
  require_relative 'unpoly/rails/engine'
5
6
  require_relative 'unpoly/rails/request_echo_headers'
6
7
  require_relative 'unpoly/rails/request_method_cookie'
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: 2.7.1.1
4
+ version: 2.7.2.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: 2022-11-21 00:00:00.000000000 Z
11
+ date: 2023-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -122,6 +122,7 @@ files:
122
122
  - assets/unpoly/unpoly.es5.js
123
123
  - assets/unpoly/unpoly.es5.min.js
124
124
  - assets/unpoly/unpoly.es6.js
125
+ - assets/unpoly/unpoly.es6.min.js
125
126
  - assets/unpoly/unpoly.js
126
127
  - assets/unpoly/unpoly.min.css
127
128
  - assets/unpoly/unpoly.min.js
@@ -137,6 +138,7 @@ files:
137
138
  - lib/unpoly/rails/error.rb
138
139
  - lib/unpoly/rails/request_echo_headers.rb
139
140
  - lib/unpoly/rails/request_method_cookie.rb
141
+ - lib/unpoly/rails/util.rb
140
142
  - lib/unpoly/rails/version.rb
141
143
  homepage: https://github.com/unpoly/unpoly-rails
142
144
  licenses: