Skip to content

Commit 95a55b0

Browse files
authored
fix: added type checking to null comparisons (#100)
1 parent e992b0e commit 95a55b0

File tree

11 files changed

+20
-20
lines changed

11 files changed

+20
-20
lines changed

src/http/body.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function HttpBody(body, init = {
4444
timeout = 0
4545
} = {}) {
4646

47-
if (body == null) {
47+
if (body === null) {
4848
// body is undefined or null
4949
body = null;
5050
} else if (isURLSearchParams(body)) {

src/http/file-reader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function ZitiFileReader( file ) {
4545

4646
var readEventHandler = function( evt ) {
4747

48-
if (evt.target.error == null) {
48+
if (evt.target.error === null) {
4949

5050
self._offset += evt.target.result.byteLength;
5151
let buf = new Buffer.from( evt.target.result );

src/http/form-data.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ ZitiFormData.prototype._trackLength = function(header, value, options) {
156156
// e.g. for streaming directly from a remote server,
157157
// w/ a known file a size, and not wanting to wait for
158158
// incoming file to finish to get its size.
159-
if (options.knownLength != null) {
159+
if (options.knownLength !== null) {
160160
valueLength += +options.knownLength;
161161
} else if (Buffer.isBuffer(value)) {
162162
valueLength = value.length;
@@ -267,7 +267,7 @@ ZitiFormData.prototype._multiPartHeader = function(field, value, options) {
267267
header = headers[prop];
268268

269269
// skip nullish headers.
270-
if (header == null) {
270+
if (header === null) {
271271
continue;
272272
}
273273

src/http/headers.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ function HttpHeaders(init = undefined) {
150150

151151
// We don't worry about converting prop to ByteString here as append()
152152
// will handle it.
153-
if (init == null) {
153+
if (init === null) {
154154
// no op
155155
} else if (typeof init === 'object') {
156156
const method = init[Symbol.iterator];
157-
if (method != null) {
157+
if (method !== null) {
158158
if (typeof method !== 'function') {
159159
throw new TypeError('Header pairs must be iterable');
160160
}
@@ -393,4 +393,4 @@ HttpHeaders.prototype.createHeadersLenient = function(obj) {
393393
HttpHeaders.prototype.getAllHeaders = function() {
394394
let pairs = getHeaders(this);
395395
return pairs;
396-
}
396+
}

src/http/internal/errors.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class SystemError extends Error {
197197
// context as the user did.
198198
Object.defineProperty(this, 'path', {
199199
get() {
200-
return context.path != null ?
200+
return context.path !== null ?
201201
context.path.toString() : context.path;
202202
},
203203
set: (value) => {
@@ -212,7 +212,7 @@ class SystemError extends Error {
212212
if (context.dest !== undefined) {
213213
Object.defineProperty(this, 'dest', {
214214
get() {
215-
return context.dest != null ?
215+
return context.dest !== null ?
216216
context.dest.toString() : context.dest;
217217
},
218218
set: (value) => {
@@ -1057,7 +1057,7 @@ E('ERR_INVALID_ARG_TYPE',
10571057
}
10581058
}
10591059

1060-
if (actual == null) {
1060+
if (actual === null) {
10611061
msg += `. Received ${actual}`;
10621062
} else if (typeof actual === 'function' && actual.name) {
10631063
msg += `. Received function ${actual.name}`;

src/http/internal/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function assertCrypto() {
9898
// Move the "slow cases" to a separate function to make sure this function gets
9999
// inlined properly. That prioritizes the common case.
100100
function normalizeEncoding(enc) {
101-
if (enc == null || enc === 'utf8' || enc === 'utf-8') return 'utf8';
101+
if (enc === null || enc === 'utf8' || enc === 'utf-8') return 'utf8';
102102
return slowCases(enc);
103103
}
104104

src/http/permessage-deflate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class PerMessageDeflate {
111111
}
112112
if (this._options.clientMaxWindowBits) {
113113
params.client_max_window_bits = this._options.clientMaxWindowBits;
114-
} else if (this._options.clientMaxWindowBits == null) {
114+
} else if (this._options.clientMaxWindowBits === null) {
115115
params.client_max_window_bits = true;
116116
}
117117

src/http/request.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ function HttpRequest(serviceNameOrConn, input, init = {}) {
108108

109109
method = method.toUpperCase();
110110

111-
if ((init.body != null || isRequest(input) && input.body !== null) && (method === 'GET' || method === 'HEAD')) {
111+
if ((init.body !== null || isRequest(input) && input.body !== null) && (method === 'GET' || method === 'HEAD')) {
112112
throw new Error('HttpRequest with GET/HEAD method cannot have body');
113113
}
114114

115-
let inputBody = init.body != null ?
115+
let inputBody = init.body !== null ?
116116
init.body :
117117
isRequest(input) && input.body !== null ?
118118
clone(input) :
@@ -129,7 +129,7 @@ function HttpRequest(serviceNameOrConn, input, init = {}) {
129129
inputBody = this.body;
130130
}
131131

132-
if (inputBody != null && !headers.has('Content-Type')) {
132+
if (inputBody !== null && !headers.has('Content-Type')) {
133133
const contentType = this.extractContentType(inputBody);
134134
if (contentType) {
135135
headers.append('Content-Type', contentType);
@@ -283,10 +283,10 @@ HttpRequest.prototype.getRequestOptions = async function() {
283283

284284
// HTTP-network-or-cache fetch steps 2.4-2.7
285285
let contentLengthValue = null;
286-
if (this.body == null && /^(POST|PUT)$/i.test(this.getMethod())) {
286+
if (this.body === null && /^(POST|PUT)$/i.test(this.getMethod())) {
287287
contentLengthValue = '0';
288288
}
289-
if (this.body != null) {
289+
if (this.body !== null) {
290290
this.body.get
291291
const totalBytes = this.getTotalBytes(this.body);
292292
if (typeof totalBytes === 'number') {

src/http/response.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function HttpResponse(body = null, opts = {}) {
4949
const status = opts.status || 200;
5050
const headers = new Headers(opts.headers)
5151

52-
if (body != null && !headers.has('Content-Type')) {
52+
if (body !== null && !headers.has('Content-Type')) {
5353
let contentType;
5454
try {
5555
contentType = extractContentType(body);

src/ui/identity_modal/file-parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ exports.parse = (file) => {
3535
var chunkReaderBlock = null;
3636

3737
var readEventHandler = function(evt) {
38-
if (evt.target.error == null) {
38+
if (evt.target.error === null) {
3939
offset += evt.target.result.length;
4040
receiveFileChunk(evt.target.result); // callback for handling read chunk
4141
} else {

0 commit comments

Comments
 (0)