Skip to content

Commit 7fecefe

Browse files
committed
[Refactor] use Object.prototype.hasOwnProperty.call
1 parent 5a5bafe commit 7fecefe

File tree

5 files changed

+53
-58
lines changed

5 files changed

+53
-58
lines changed

lib/form_data.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ FormData.prototype._trackLength = function(header, value, options) {
101101
FormData.LINE_BREAK.length;
102102

103103
// empty or either doesn't have path or not an http response
104-
if (!value || ( !value.path && !(value.readable && value.hasOwnProperty('httpVersion')) )) {
104+
if (!value || ( !value.path && !(value.readable && Object.prototype.hasOwnProperty.call(value, 'httpVersion')) )) {
105105
return;
106106
}
107107

@@ -112,8 +112,7 @@ FormData.prototype._trackLength = function(header, value, options) {
112112
};
113113

114114
FormData.prototype._lengthRetriever = function(value, callback) {
115-
116-
if (value.hasOwnProperty('fd')) {
115+
if (Object.prototype.hasOwnProperty.call(value, 'fd')) {
117116

118117
// take read range into a account
119118
// `end` = Infinity –> read file till the end
@@ -148,11 +147,11 @@ FormData.prototype._lengthRetriever = function(value, callback) {
148147
}
149148

150149
// or http response
151-
} else if (value.hasOwnProperty('httpVersion')) {
150+
} else if (Object.prototype.hasOwnProperty.call(value, 'httpVersion')) {
152151
callback(null, +value.headers['content-length']);
153152

154153
// or request stream http://github.com/mikeal/request
155-
} else if (value.hasOwnProperty('httpModule')) {
154+
} else if (Object.prototype.hasOwnProperty.call(value, 'httpModule')) {
156155
// wait till response come back
157156
value.on('response', function(response) {
158157
value.pause();
@@ -192,22 +191,23 @@ FormData.prototype._multiPartHeader = function(field, value, options) {
192191

193192
var header;
194193
for (var prop in headers) {
195-
if (!headers.hasOwnProperty(prop)) continue;
196-
header = headers[prop];
194+
if (Object.prototype.hasOwnProperty.call(headers, prop)) {
195+
header = headers[prop];
197196

198-
// skip nullish headers.
199-
if (header == null) {
200-
continue;
201-
}
197+
// skip nullish headers.
198+
if (header == null) {
199+
continue;
200+
}
202201

203-
// convert all headers to arrays.
204-
if (!Array.isArray(header)) {
205-
header = [header];
206-
}
202+
// convert all headers to arrays.
203+
if (!Array.isArray(header)) {
204+
header = [header];
205+
}
207206

208-
// add non-empty headers.
209-
if (header.length) {
210-
contents += prop + ': ' + header.join('; ') + FormData.LINE_BREAK;
207+
// add non-empty headers.
208+
if (header.length) {
209+
contents += prop + ': ' + header.join('; ') + FormData.LINE_BREAK;
210+
}
211211
}
212212
}
213213

@@ -228,7 +228,7 @@ FormData.prototype._getContentDisposition = function(value, options) {
228228
// formidable and the browser add a name property
229229
// fs- and request- streams have path property
230230
filename = path.basename(options.filename || value.name || value.path);
231-
} else if (value.readable && value.hasOwnProperty('httpVersion')) {
231+
} else if (value.readable && Object.prototype.hasOwnProperty.call(value, 'httpVersion')) {
232232
// or try http response
233233
filename = path.basename(value.client._httpMessage.path || '');
234234
}
@@ -256,7 +256,7 @@ FormData.prototype._getContentType = function(value, options) {
256256
}
257257

258258
// or if it's http-reponse
259-
if (!contentType && value.readable && value.hasOwnProperty('httpVersion')) {
259+
if (!contentType && value.readable && Object.prototype.hasOwnProperty.call(value, 'httpVersion')) {
260260
contentType = value.headers['content-type'];
261261
}
262262

@@ -297,7 +297,7 @@ FormData.prototype.getHeaders = function(userHeaders) {
297297
};
298298

299299
for (header in userHeaders) {
300-
if (userHeaders.hasOwnProperty(header)) {
300+
if (Object.prototype.hasOwnProperty.call(userHeaders, header)) {
301301
formHeaders[header.toLowerCase()] = userHeaders[header];
302302
}
303303
}

test/common.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ common.testFields = function (FIELDS, callback) {
4040
var incomingForm = new IncomingForm({uploadDir: common.dir.tmp});
4141

4242
incomingForm.parse(req);
43-
43+
4444
common.actions.checkForm(incomingForm, FIELDS, function (fieldsChecked) {
4545
// keep track of number of the processed fields
4646
callback(fieldsPassed - fieldsChecked);
@@ -55,18 +55,17 @@ common.testFields = function (FIELDS, callback) {
5555
common.actions = {};
5656

5757
// generic form field population
58-
common.actions.populateFields = function(form, fields)
59-
{
58+
common.actions.populateFields = function (form, fields) {
6059
var field;
6160
for (var name in fields) {
62-
if (!fields.hasOwnProperty(name)) { continue; }
63-
64-
field = fields[name];
65-
// important to append ReadStreams within the same tick
66-
if ((typeof field.value == 'function')) {
67-
field.value = field.value();
61+
if (Object.prototype.hasOwnProperty.call(fields, name)) {
62+
field = fields[name];
63+
// important to append ReadStreams within the same tick
64+
if ((typeof field.value == 'function')) {
65+
field.value = field.value();
66+
}
67+
form.append(name, field.value);
6868
}
69-
form.append(name, field.value);
7069
}
7170
};
7271

test/integration/test-custom-content-type.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,15 @@ server.listen(common.port, function() {
6767

6868
var form = new FormData();
6969

70-
var field;
7170
for (var name in FIELDS) {
72-
if (!FIELDS.hasOwnProperty(name)) { continue; }
73-
74-
field = FIELDS[name];
75-
// important to append ReadStreams within the same tick
76-
if ((typeof field.value == 'function')) {
77-
field.value = field.value();
71+
if (Object.prototype.hasOwnProperty.call(FIELDS, name)) {
72+
var field = FIELDS[name];
73+
// important to append ReadStreams within the same tick
74+
if ((typeof field.value == 'function')) {
75+
field.value = field.value();
76+
}
77+
form.append(name, field.value, field.options);
7878
}
79-
form.append(name, field.value, field.options);
8079
}
8180

8281
// custom params object passed to submit

test/integration/test-pipe.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,15 @@ server.listen(common.port, function() {
4949

5050
var form = new FormData();
5151

52-
var field;
5352
for (var name in FIELDS) {
54-
if (!FIELDS.hasOwnProperty(name)) { continue; }
55-
56-
field = FIELDS[name];
57-
// important to append ReadStreams within the same tick
58-
if ((typeof field.value == 'function')) {
59-
field.value = field.value();
53+
if (Object.prototype.hasOwnProperty.call(FIELDS, name)) {
54+
var field = FIELDS[name];
55+
// important to append ReadStreams within the same tick
56+
if ((typeof field.value == 'function')) {
57+
field.value = field.value();
58+
}
59+
form.append(name, field.value);
6060
}
61-
form.append(name, field.value);
6261
}
6362

6463
var req = http.request({

test/integration/test-ranged-filestream.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,18 @@ server.listen(common.port, function() {
8080

8181
// add test subjects to the form
8282
for (name in testSubjects) {
83-
if (!testSubjects.hasOwnProperty(name)) {
84-
continue;
85-
}
86-
87-
options = {encoding: 'utf8'};
83+
if (Object.prototype.hasOwnProperty.call(testSubjects, name)) {
84+
options = {encoding: 'utf8'};
8885

89-
if (testSubjects[name].start) { options.start = testSubjects[name].start; }
90-
if (testSubjects[name].end) { options.end = testSubjects[name].end; }
86+
if (testSubjects[name].start) { options.start = testSubjects[name].start; }
87+
if (testSubjects[name].end) { options.end = testSubjects[name].end; }
9188

92-
form.append(name, testSubjects[name].fsStream = fs.createReadStream(common.dir.fixture + '/' + testSubjects[name].file, options));
89+
form.append(name, testSubjects[name].fsStream = fs.createReadStream(common.dir.fixture + '/' + testSubjects[name].file, options));
9390

94-
// calculate data size
95-
testSubjects[name].readSize = 0;
96-
testSubjects[name].fsStream.on('data', readSizeAccumulator.bind(testSubjects[name]));
91+
// calculate data size
92+
testSubjects[name].readSize = 0;
93+
testSubjects[name].fsStream.on('data', readSizeAccumulator.bind(testSubjects[name]));
94+
}
9795
}
9896

9997
form.submit('http://localhost:' + common.port + '/', function(err, res) {

0 commit comments

Comments
 (0)