execjs-pcruntime 0.2.0 → 0.2.1
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aec9e69936452420277727dacd0c7d27331b7766c8008c433cd840a8c6f38f45
|
4
|
+
data.tar.gz: 75271e7344781d9338c09263b1ac036355147cd228ae0b7581272cfb3dc53a1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
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 =
|
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
|
-
|
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)
|
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;
|