go_to_param 0.2.0 → 0.3.0

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
  SHA1:
3
- metadata.gz: 05ddd7d3e4b2514e5f5136af63f0263f0bde08c9
4
- data.tar.gz: 47acd514926425787274fa1452252147007ed803
3
+ metadata.gz: 8ff657dfce2b1757a637ff58b8614803f96415b4
4
+ data.tar.gz: 446aaba35e959473a3ec0df17e3ada34ee91a831
5
5
  SHA512:
6
- metadata.gz: 2c7e6949c134e0d72dce393533870c28860e8ea44bb51198e42869eba80c36bfee6dc09cb4dd5f288daec909b0f11f31087cfbde871dbbb56d5bcb24241421cb
7
- data.tar.gz: ef121087d69984d484e37a647396076cd528eec877889185abf22f5cdff43bc287611bd4543e5707ce6ad635535d90f0044593dc872a2e8df5c89e95c4802de3
6
+ metadata.gz: 0d882496e336ab925a45599ad950c2c2541c8b6a3b798eea41b1cf75aa7982747b0c9a3481c4c9e17090deb3ed84d3610b5f74054497ac79b3b422ac95ee7e9e
7
+ data.tar.gz: 405bed370bc54b4a81c0ddecc8968ad31ea3e7d0de39207433ec77b65651fd296026299a474196a9410db868f97862c79796f1a9f465c3cb13a53ddb055c3461
@@ -1,3 +1,3 @@
1
1
  module GoToParam
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/go_to_param.rb CHANGED
@@ -47,7 +47,7 @@ module GoToParam
47
47
 
48
48
  def go_to_here_path(additional_query_params = {})
49
49
  if request.get?
50
- _go_to_add_query_string_from_hash(request.fullpath, additional_query_params)
50
+ _go_to_add_query_string_from_hash(_go_to_fullpath, additional_query_params)
51
51
  else
52
52
  nil
53
53
  end
@@ -67,4 +67,11 @@ module GoToParam
67
67
  [ path, separator, query_string ].join
68
68
  end
69
69
  end
70
+
71
+ # Prevent encoding errors ("incompatible character encodings: UTF-8 and ASCII-8BIT") for certain malformed requests.
72
+ # Inspired by https://github.com/discourse/discourse/commit/090dc80f8a23dbb3ad703efbac990aa917c06505
73
+ def _go_to_fullpath
74
+ path = request.fullpath
75
+ path.dup.force_encoding("UTF-8").scrub
76
+ end
70
77
  end
@@ -99,6 +99,17 @@ describe GoToParam do
99
99
  expect(controller.go_to_here_params(bar: 3)).to eq({ go_to: "/example?foo&bar=3" })
100
100
  end
101
101
 
102
+ it "makes sure the go_to path is valid UTF-8" do
103
+ weird_path = "\xE0\x80\x80weird\330stuff".force_encoding("ASCII-8BIT")
104
+ replacement = "\uFFFD" # The Unicode 'Replacement Character'
105
+
106
+ controller.request = double(get?: true, fullpath: weird_path)
107
+
108
+ go_to_value = controller.go_to_here_params[:go_to]
109
+
110
+ expect(go_to_value.encoding).to eq(Encoding::UTF_8)
111
+ expect(go_to_value).to eq("#{replacement}#{replacement}#{replacement}weird#{replacement}stuff")
112
+ end
102
113
  end
103
114
 
104
115
  describe "#go_to_path" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: go_to_param
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrik N
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-20 00:00:00.000000000 Z
11
+ date: 2015-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler