Skip to content

Commit bac9344

Browse files
XadillaXMylesBorins
authored andcommitted
test: check endless loop while writing empty string
Refs: #18673 Backport-PR-URL: #20456 PR-URL: #18924 Refs: #18673 Refs: https://github.com/nodejs/node/blob/v9.5.0/src/node_http2.cc#L1481-L1484 Refs: https://github.com/nodejs/node/blob/v9.5.0/lib/_http_outgoing.js#L659-L661 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent dc3f6c0 commit bac9344

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
'use strict';
2+
3+
const assert = require('assert');
4+
const http2 = require('http2');
5+
6+
const common = require('../common');
7+
if (!common.hasCrypto)
8+
common.skip('missing crypto');
9+
10+
for (const chunkSequence of [
11+
[ '' ],
12+
[ '', '' ]
13+
]) {
14+
const server = http2.createServer();
15+
server.on('stream', common.mustCall((stream, headers, flags) => {
16+
stream.respond({ 'content-type': 'text/html' });
17+
18+
let data = '';
19+
stream.on('data', common.mustNotCall((chunk) => {
20+
data += chunk.toString();
21+
}));
22+
stream.on('end', common.mustCall(() => {
23+
stream.end(`"${data}"`);
24+
}));
25+
}));
26+
27+
server.listen(0, common.mustCall(() => {
28+
const port = server.address().port;
29+
const client = http2.connect(`http://localhost:${port}`);
30+
31+
const req = client.request({
32+
':method': 'POST',
33+
':path': '/'
34+
});
35+
36+
req.on('response', common.mustCall((headers) => {
37+
assert.strictEqual(headers[':status'], 200);
38+
assert.strictEqual(headers['content-type'], 'text/html');
39+
}));
40+
41+
let data = '';
42+
req.setEncoding('utf8');
43+
req.on('data', common.mustCallAtLeast((d) => data += d));
44+
req.on('end', common.mustCall(() => {
45+
assert.strictEqual(data, '""');
46+
server.close();
47+
client.close();
48+
}));
49+
50+
for (const chunk of chunkSequence)
51+
req.write(chunk);
52+
req.end();
53+
}));
54+
}

0 commit comments

Comments
 (0)