Skip to content

Commit 8d595bb

Browse files
XadillaXaddaleax
authored andcommitted
test: check endless loop while writing empty string
Refs: #18673 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 8bc930c commit 8d595bb

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
'use strict';
2+
3+
constassert=require('assert');
4+
consthttp2=require('http2');
5+
6+
constcommon=require('../common');
7+
if(!common.hasCrypto)
8+
common.skip('missing crypto');
9+
10+
for(constchunkSequenceof[
11+
[''],
12+
['','']
13+
]){
14+
constserver=http2.createServer();
15+
server.on('stream',common.mustCall((stream,headers,flags)=>{
16+
stream.respond({'content-type': 'text/html'});
17+
18+
letdata='';
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+
constport=server.address().port;
29+
constclient=http2.connect(`http://localhost:${port}`);
30+
31+
constreq=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+
letdata='';
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(constchunkofchunkSequence)
51+
req.write(chunk);
52+
req.end();
53+
}));
54+
}

0 commit comments

Comments
 (0)