unpoly-rails 3.0.0.rc1 → 3.0.0.rc3

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.
@@ -102,7 +102,7 @@ module Unpoly
102
102
 
103
103
  def parse(raw)
104
104
  if raw.present?
105
- result = ActiveSupport::JSON.decode(raw)
105
+ result = Util.json_decode(raw)
106
106
  elsif @default
107
107
  result = instance_exec(&@default)
108
108
  end
@@ -116,7 +116,7 @@ module Unpoly
116
116
 
117
117
  def stringify(value)
118
118
  unless value.nil?
119
- ActiveSupport::JSON.encode(value)
119
+ Util.safe_json_encode(value)
120
120
  end
121
121
  end
122
122
 
@@ -133,7 +133,7 @@ module Unpoly
133
133
 
134
134
  def parse(raw)
135
135
  if raw.present?
136
- result = ActiveSupport::JSON.decode(raw)
136
+ result = Util.json_decode(raw)
137
137
  elsif @default
138
138
  result = instance_exec(&@default)
139
139
  end
@@ -143,7 +143,7 @@ module Unpoly
143
143
 
144
144
  def stringify(value)
145
145
  unless value.nil?
146
- ActiveSupport::JSON.encode(value)
146
+ Util.safe_json_encode(value)
147
147
  end
148
148
  end
149
149
 
@@ -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
@@ -243,7 +243,7 @@ module Unpoly
243
243
  def title=(new_title)
244
244
  # We don't make this a field since it belongs to *this* response
245
245
  # and should not survive a redirect.
246
- response.headers['X-Up-Title'] = new_title
246
+ response.headers['X-Up-Title'] = Util.safe_json_encode(new_title)
247
247
  end
248
248
 
249
249
  def after_action
@@ -18,9 +18,13 @@ module Unpoly
18
18
  end
19
19
 
20
20
  private
21
-
21
+
22
22
  def set_up_request_echo_headers
23
- response.headers['X-Up-Location'] = up.request_url_without_up_params
23
+ request_url_without_up_params = up.request_url_without_up_params
24
+ unless request_url_without_up_params == request.original_url
25
+ response.headers['X-Up-Location'] = up.request_url_without_up_params
26
+ end
27
+
24
28
  response.headers['X-Up-Method'] = request.method
25
29
  end
26
30
 
@@ -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 = '3.0.0.rc1'
7
+ VERSION = '3.0.0.rc3'
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: 3.0.0.rc1
4
+ version: 3.0.0.rc3
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-02-09 00:00:00.000000000 Z
11
+ date: 2023-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -136,6 +136,7 @@ files:
136
136
  - lib/unpoly/rails/error.rb
137
137
  - lib/unpoly/rails/request_echo_headers.rb
138
138
  - lib/unpoly/rails/request_method_cookie.rb
139
+ - lib/unpoly/rails/util.rb
139
140
  - lib/unpoly/rails/version.rb
140
141
  homepage: https://github.com/unpoly/unpoly-rails
141
142
  licenses: