Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d79c330

Browse filesBrowse files
rickyeshimself65
authored andcommitted
http2: refactor state code validation for the http2Stream class
PR-URL: #33535 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Zeyu Yang <himself65@outlook.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent b0b268f commit d79c330
Copy full SHA for d79c330

File tree

Expand file treeCollapse file tree

2 files changed

+25
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+25
-4
lines changed
Open diff view settings
Collapse file

‎lib/internal/http2/core.js‎

Copy file name to clipboardExpand all lines: lib/internal/http2/core.js
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ const {
9999
},
100100
hideStackFrames
101101
} = require('internal/errors');
102-
const { validateNumber,
102+
const { validateInteger,
103+
validateNumber,
103104
validateString,
104105
validateUint32,
105106
isUint32,
@@ -2093,9 +2094,8 @@ class Http2Stream extends Duplex {
20932094
// close, it is still possible to queue up PRIORITY and RST_STREAM frames,
20942095
// but no DATA and HEADERS frames may be sent.
20952096
close(code = NGHTTP2_NO_ERROR, callback) {
2096-
validateNumber(code, 'code');
2097-
if (code < 0 || code > kMaxInt)
2098-
throw new ERR_OUT_OF_RANGE('code', `>= 0 && <= ${kMaxInt}`, code);
2097+
validateInteger(code, 'code', 0, kMaxInt);
2098+
20992099
if (callback !== undefined && typeof callback !== 'function')
21002100
throw new ERR_INVALID_CALLBACK(callback);
21012101

Collapse file

‎test/parallel/test-http2-invalidargtypes-errors.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http2-invalidargtypes-errors.js
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,27 @@ server.on('stream', common.mustCall((stream) => {
1818
"Received type string ('string')"
1919
}
2020
);
21+
assert.throws(
22+
() => stream.close(1.01),
23+
{
24+
code: 'ERR_OUT_OF_RANGE',
25+
name: 'RangeError',
26+
message: 'The value of "code" is out of range. It must be an integer. ' +
27+
'Received 1.01'
28+
}
29+
);
30+
[-1, 2 ** 32].forEach((code) => {
31+
assert.throws(
32+
() => stream.close(code),
33+
{
34+
code: 'ERR_OUT_OF_RANGE',
35+
name: 'RangeError',
36+
message: 'The value of "code" is out of range. ' +
37+
'It must be >= 0 && <= 4294967295. ' +
38+
`Received ${code}`
39+
}
40+
);
41+
});
2142
stream.respond();
2243
stream.end('ok');
2344
}));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.