execjs-pcruntime 0.2.0 → 0.2.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: 33a36bdd0ffeafecbae5dff76e27596b8c1d5087e3e9fd7e935dac8d41284f63
4
- data.tar.gz: 5f0f2527ade99ae2d93fc997db5c345e3e0348fd6cfa1582369e03cb34481b10
3
+ metadata.gz: aec9e69936452420277727dacd0c7d27331b7766c8008c433cd840a8c6f38f45
4
+ data.tar.gz: 75271e7344781d9338c09263b1ac036355147cd228ae0b7581272cfb3dc53a1a
5
5
  SHA512:
6
- metadata.gz: d7216ba79372073c2a3213b11173f86fe20cdbb2267ffd5b2c8747acf4f30fec08117ee6dea6e37fe4426e2149d9f9b2ca476efb2712531b22626210a36f0450
7
- data.tar.gz: 7c9741fe563eb0eb6e4633bc9ddd9d8bfd37411f9dfd9ecc72753313b71ee2a13d6e66d8aaa7f975f121d9f415f38307a04f3a0a035ee72b407524ffc0be5941
6
+ metadata.gz: b8a8075e90042f2e6183dae5faf84e3c8749b0b8138e9f30fc3499287eef1cf2a3120f5bc7d5c9e3427ce9fe088ad0b28f38cfa3a4471df6b9c25cb4b3c38006
7
+ data.tar.gz: '088fe43e02e523346e26ad05cd8617aa3298e046b90760cdafcdb7d0f74fd9a4b3c0ab56e8489e65ac51493850611faf267bd1899a3486088153ddc9fd594ad0'
@@ -158,7 +158,10 @@ module ExecJS
158
158
  request['Connection'] = 'close'
159
159
  unless content_type.nil?
160
160
  request['Content-Type'] = content_type
161
- request.body = body
161
+ # URI.encode_www_form_component replaces space(U+0020) into '+' (not '%20')
162
+ # but decodeURIComponent(in JavaScript) cannot decode '+' into space
163
+ # so, replace '+' into '%20'
164
+ request.body = URI.encode_www_form_component(body).gsub('+', '%20')
162
165
  end
163
166
 
164
167
  # Net::HTTPGenericRequest#exec
@@ -172,13 +175,13 @@ module ExecJS
172
175
  end while response.is_a?(Net::HTTPContinue)
173
176
  # rubocop:enable Lint/Loop
174
177
  response.reading_body(socket, request.response_body_permitted?) {}
178
+ result = URI.decode_www_form_component response.body
175
179
 
176
180
  if response.code == '200'
177
- result = response.body
178
- ::JSON.parse(response.body, create_additions: false) if /\S/.match?(result)
181
+ ::JSON.parse(result, create_additions: false) if /\S/.match?(result)
179
182
  else
180
183
  # expects ErrorMessage\0StackTrace =~ response.body
181
- message, stack = response.body.split "\0"
184
+ message, stack = result.split "\0"
182
185
  error_class = /SyntaxError:/.match?(message) ? RuntimeError : ProgramError
183
186
  error = error_class.new(message)
184
187
  error.set_backtrace(stack)
@@ -14,16 +14,17 @@ const server = http.createServer(function (req, res) {
14
14
  req.on('data', (data) => allData += data);
15
15
  req.on('end', () => {
16
16
  try {
17
- const result = vm.runInContext(allData, context, "(execjs)");
17
+ // Percent-encoding HTTP requests and responses to avoid invalid UTF-8 sequences.
18
+ const result = vm.runInContext(decodeURIComponent(allData), context, "(execjs)");
18
19
  res.statusCode = 200;
19
20
  res.setHeader('Content-Type', 'application/json');
20
- res.end(JSON.stringify(result), 'utf-8');
21
+ res.end(encodeURIComponent(JSON.stringify(result) || null));
21
22
  } catch (e) {
22
23
  res.statusCode = 500;
23
24
  res.setHeader('Content-Type', 'text/plain');
24
25
  // to split by \0 on Ruby side
25
26
  // see context_process_runtime.rb:179
26
- res.end(e.toString() + "\0" + (e.stack || ""));
27
+ res.end(encodeURIComponent(e.toString() + "\0" + (e.stack || "")));
27
28
  }
28
29
  });
29
30
  break;
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Execjs
4
4
  module PCRuntime
5
- VERSION = '0.2.0'
5
+ VERSION = '0.2.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: execjs-pcruntime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - White-Green