intranet-core 2.1.0 → 2.1.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
  SHA1:
3
- metadata.gz: f2a43e959280a59c8d78aca617cfe1cce627a91f
4
- data.tar.gz: 0c6a14aceaf6386eafdf9df74d44348f7cd4e19c
3
+ metadata.gz: 33d4ae0d118eb6df517196db16108065df87c47d
4
+ data.tar.gz: 1bc931bf597059ef00c54368e8e8548548c66fa2
5
5
  SHA512:
6
- metadata.gz: e7aa8f0cf791ce22fd5098176bcc1431f6742e6268f6a244d731a211c6b28510505885d216b2b1ef8f2a2fbd4e321b5f08552c9a7d20d8673b84a34f1d0f243e
7
- data.tar.gz: 5af64c4232442843117fbd865cd06c228d29ef682a647169c2f78c5dbfca9113214864ca673c8c75338ee7df4a87558fada653391565b0c77138e581c2ae77a4
6
+ metadata.gz: ec89f5cbf9fb1466b3c22d475380980d44c9d1a369d126c276cb41c719ecc0e193609a17eaffffd1e6f1f7ba74b6d26b95744ab06304bbaff2216d6215038204
7
+ data.tar.gz: e3baf947cbd08ccc04a96cbaca311030560e70e1b7cd586e6e14a16429b56df42b9c2c7eccec77f1e246a6a335d688c0f734e2d44ff1eef9c06eebc132dd22d5
@@ -26,12 +26,12 @@ module Intranet
26
26
  # We could use request.request_uri (which is a URI object) but its path is not normalized
27
27
  # (it may contain '../' or event start with '..'). Hence we use request.path which has been
28
28
  # normalized with HTTPUtils::normalize_path, and request.query for the URL parameters.
29
- path = request.path
29
+ path = request.path.force_encoding('UTF-8')
30
30
  path += 'index.html' if path.end_with?('/')
31
31
 
32
32
  handle_redirections(request, path, response, '/index.html' => @builder.home_url)
33
33
 
34
- status, content_type, body = @builder.do_get(path, request.query)
34
+ status, content_type, body = @builder.do_get(path, encode_query(request.query))
35
35
 
36
36
  raise WEBrick::HTTPStatus[status] if WEBrick::HTTPStatus.error?(status)
37
37
 
@@ -51,6 +51,13 @@ module Intranet
51
51
  rescue KeyError # rubocop:disable Lint/HandleExceptions
52
52
  # nothing to do
53
53
  end
54
+
55
+ # Reencodes the +query+ in UTF-8 strings for compatibility.
56
+ def encode_query(query)
57
+ query.map do |k, v|
58
+ { k.dup.force_encoding('UTF-8') => v.force_encoding('UTF-8') }
59
+ end.reduce({}, :merge)
60
+ end
54
61
  end
55
62
  end
56
63
  end
@@ -6,7 +6,7 @@ module Intranet
6
6
  NAME = 'intranet-core'
7
7
 
8
8
  # The version of the gem, according to semantic versionning.
9
- VERSION = '2.1.0'
9
+ VERSION = '2.1.1'
10
10
 
11
11
  # The URL of the gem homepage.
12
12
  HOMEPAGE_URL = 'https://rubygems.org/gems/intranet-core'
@@ -178,7 +178,7 @@ RSpec.describe Intranet::Core do
178
178
  end
179
179
 
180
180
  context 'given a valid and registered module' do
181
- it 'should be called with the URL path and query' do
181
+ it 'should be called with the decoded URL path and query in UTF-8 encoding' do
182
182
  begin
183
183
  @intranet = described_class.new(Intranet::Logger.new(Intranet::Logger::FATAL))
184
184
  responder = Intranet::TestResponder.new('/index.html' => [200, 'text/html', ''])
@@ -190,25 +190,17 @@ RSpec.describe Intranet::Core do
190
190
  end
191
191
 
192
192
  socket = TCPSocket.new('localhost', @intranet.port)
193
- socket.puts("GET /responder/query?var1=value1&var2=value2 HTTP/1.1\r\n" \
193
+ socket.puts("GET /responder/query%20t?var1=value1&var2=value2 HTTP/1.1\r\n" \
194
194
  "Host: localhost:#{@intranet.port}\r\n\r\n")
195
195
  expect(socket.gets).to include('HTTP/1.1 200 OK')
196
196
  while (line = socket.gets.chomp) # consume HTTP response headers
197
197
  break if line.empty?
198
198
  end
199
199
  line = socket.gets.chomp
200
- expect(line).to eql({ 'var1' => 'value1', 'var2' => 'value2' }.to_s)
201
- socket.close
202
-
203
- socket = TCPSocket.new('localhost', @intranet.port)
204
- socket.puts("GET /responder/query?foo=bar&baz=boz HTTP/1.1\r\n" \
205
- "Host: localhost:#{@intranet.port}\r\n\r\n")
206
- expect(socket.gets).to include('HTTP/1.1 200 OK')
207
- while (line = socket.gets.chomp) # consume HTTP response headers
208
- break if line.empty?
209
- end
210
- line = socket.gets.chomp
211
- expect(line).to eql({ 'foo' => 'bar', 'baz' => 'boz' }.to_s)
200
+ expect(line).to eql(
201
+ 'PATH=/query t (UTF-8), ' \
202
+ 'QUERY={var1 (UTF-8) => value1 (UTF-8),var2 (UTF-8) => value2 (UTF-8)}'
203
+ )
212
204
  ensure
213
205
  socket.close
214
206
  Thread.kill(thread)
@@ -42,8 +42,8 @@ module Intranet
42
42
  end
43
43
 
44
44
  def generate_page(path, query)
45
- if path == '/query'
46
- [200, 'text/plain', query.to_s + "\r\n"]
45
+ if path.start_with?('/query')
46
+ [200, 'text/plain', dump_with_encoding(path, query)]
47
47
  else
48
48
  @responses.fetch(path)
49
49
  end
@@ -58,5 +58,13 @@ module Intranet
58
58
  def js_dependencies
59
59
  super + @extra_js
60
60
  end
61
+
62
+ private
63
+
64
+ def dump_with_encoding(path, query)
65
+ "PATH=#{path} (#{path.encoding}), QUERY={" +
66
+ query.map { |k, v| "#{k} (#{k.encoding}) => #{v} (#{v.encoding})" }.join(',') +
67
+ "}\r\n"
68
+ end
61
69
  end
62
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intranet-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ebling Mis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-17 00:00:00.000000000 Z
11
+ date: 2019-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: haml