Fix: Lint no-prototype-builtins (#5920)
* Fix: Lint no-prototype-builtins Closes: https://github.com/parse-community/parse-server/issues/5842 Reference: https://eslint.org/docs/rules/no-prototype-builtins * replace Object.hasOwnProperty.call
This commit is contained in:
committed by
Antonio Davi Macedo Coelho de Castro
parent
4bffdce047
commit
cf6e79ee75
@@ -67,7 +67,7 @@ function loadAuthAdapter(provider, authOptions) {
|
||||
const providerOptions = authOptions[provider];
|
||||
if (
|
||||
providerOptions &&
|
||||
providerOptions.hasOwnProperty('oauth2') &&
|
||||
Object.prototype.hasOwnProperty.call(providerOptions, 'oauth2') &&
|
||||
providerOptions['oauth2'] === true
|
||||
) {
|
||||
defaultAdapter = oauth2;
|
||||
|
||||
@@ -279,7 +279,7 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
delete existingIndexes[name];
|
||||
} else {
|
||||
Object.keys(field).forEach(key => {
|
||||
if (!fields.hasOwnProperty(key)) {
|
||||
if (!Object.prototype.hasOwnProperty.call(fields, key)) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_QUERY,
|
||||
`Field ${key} does not exist, cannot add index.`
|
||||
@@ -795,7 +795,7 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
)
|
||||
.then(results => {
|
||||
results.forEach(result => {
|
||||
if (result.hasOwnProperty('_id')) {
|
||||
if (Object.prototype.hasOwnProperty.call(result, '_id')) {
|
||||
if (isPointerField && result._id) {
|
||||
result._id = result._id.split('$')[1];
|
||||
}
|
||||
@@ -1024,7 +1024,7 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
const existingIndexes = schema.indexes;
|
||||
for (const key in existingIndexes) {
|
||||
const index = existingIndexes[key];
|
||||
if (index.hasOwnProperty(fieldName)) {
|
||||
if (Object.prototype.hasOwnProperty.call(index, fieldName)) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1282,7 +1282,7 @@ const nestedMongoObjectToNestedParseObject = mongoObject => {
|
||||
}
|
||||
|
||||
if (
|
||||
mongoObject.hasOwnProperty('__type') &&
|
||||
Object.prototype.hasOwnProperty.call(mongoObject, '__type') &&
|
||||
mongoObject.__type == 'Date' &&
|
||||
mongoObject.iso instanceof Date
|
||||
) {
|
||||
|
||||
@@ -903,7 +903,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
|
||||
delete existingIndexes[name];
|
||||
} else {
|
||||
Object.keys(field).forEach(key => {
|
||||
if (!fields.hasOwnProperty(key)) {
|
||||
if (!Object.prototype.hasOwnProperty.call(fields, key)) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_QUERY,
|
||||
`Field ${key} does not exist, cannot add index.`
|
||||
@@ -2219,7 +2219,12 @@ export class PostgresStorageAdapter implements StorageAdapter {
|
||||
}
|
||||
if (stage.$match) {
|
||||
const patterns = [];
|
||||
const orOrAnd = stage.$match.hasOwnProperty('$or') ? ' OR ' : ' AND ';
|
||||
const orOrAnd = Object.prototype.hasOwnProperty.call(
|
||||
stage.$match,
|
||||
'$or'
|
||||
)
|
||||
? ' OR '
|
||||
: ' AND ';
|
||||
|
||||
if (stage.$match.$or) {
|
||||
const collapse = {};
|
||||
@@ -2294,7 +2299,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
|
||||
)
|
||||
.then(results => {
|
||||
results.forEach(result => {
|
||||
if (!result.hasOwnProperty('objectId')) {
|
||||
if (!Object.prototype.hasOwnProperty.call(result, 'objectId')) {
|
||||
result.objectId = null;
|
||||
}
|
||||
if (groupValues) {
|
||||
|
||||
@@ -119,7 +119,7 @@ const validateQuery = (
|
||||
*/
|
||||
Object.keys(query).forEach(key => {
|
||||
const noCollisions = !query.$or.some(subq =>
|
||||
Object.hasOwnProperty.call(subq, key)
|
||||
Object.prototype.hasOwnProperty.call(subq, key)
|
||||
);
|
||||
let hasNears = false;
|
||||
if (query[key] != null && typeof query[key] == 'object') {
|
||||
@@ -1487,7 +1487,7 @@ class DatabaseController {
|
||||
[key]: userPointer,
|
||||
};
|
||||
// if we already have a constraint on the key, use the $and
|
||||
if (query.hasOwnProperty(key)) {
|
||||
if (Object.prototype.hasOwnProperty.call(query, key)) {
|
||||
return { $and: [q, query] };
|
||||
}
|
||||
// otherwise just add the constaint
|
||||
|
||||
@@ -32,7 +32,10 @@ export class PushController {
|
||||
}
|
||||
|
||||
// Immediate push
|
||||
if (body.expiration_interval && !body.hasOwnProperty('push_time')) {
|
||||
if (
|
||||
body.expiration_interval &&
|
||||
!Object.prototype.hasOwnProperty.call(body, 'push_time')
|
||||
) {
|
||||
const ttlMs = body.expiration_interval * 1000;
|
||||
body.expiration_time = new Date(now.valueOf() + ttlMs).valueOf();
|
||||
}
|
||||
@@ -121,7 +124,7 @@ export class PushController {
|
||||
})
|
||||
.then(() => {
|
||||
if (
|
||||
body.hasOwnProperty('push_time') &&
|
||||
Object.prototype.hasOwnProperty.call(body, 'push_time') &&
|
||||
config.hasPushScheduledSupport
|
||||
) {
|
||||
return Promise.resolve();
|
||||
@@ -147,7 +150,10 @@ export class PushController {
|
||||
* @returns {Number|undefined} The expiration time if it exists in the request
|
||||
*/
|
||||
static getExpirationTime(body = {}) {
|
||||
var hasExpirationTime = body.hasOwnProperty('expiration_time');
|
||||
var hasExpirationTime = Object.prototype.hasOwnProperty.call(
|
||||
body,
|
||||
'expiration_time'
|
||||
);
|
||||
if (!hasExpirationTime) {
|
||||
return;
|
||||
}
|
||||
@@ -174,7 +180,10 @@ export class PushController {
|
||||
}
|
||||
|
||||
static getExpirationInterval(body = {}) {
|
||||
const hasExpirationInterval = body.hasOwnProperty('expiration_interval');
|
||||
const hasExpirationInterval = Object.prototype.hasOwnProperty.call(
|
||||
body,
|
||||
'expiration_interval'
|
||||
);
|
||||
if (!hasExpirationInterval) {
|
||||
return;
|
||||
}
|
||||
@@ -198,7 +207,7 @@ export class PushController {
|
||||
* @returns {Number|undefined} The push time if it exists in the request
|
||||
*/
|
||||
static getPushTime(body = {}) {
|
||||
var hasPushTime = body.hasOwnProperty('push_time');
|
||||
var hasPushTime = Object.prototype.hasOwnProperty.call(body, 'push_time');
|
||||
if (!hasPushTime) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -600,7 +600,10 @@ class ParseLiveQueryServer {
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (!request || !request.hasOwnProperty('masterKey')) {
|
||||
if (
|
||||
!request ||
|
||||
!Object.prototype.hasOwnProperty.call(request, 'masterKey')
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return request.masterKey === validKeyPairs.get('masterKey');
|
||||
@@ -623,7 +626,7 @@ class ParseLiveQueryServer {
|
||||
|
||||
_handleSubscribe(parseWebsocket: any, request: any): any {
|
||||
// If we can not find this client, return error to client
|
||||
if (!parseWebsocket.hasOwnProperty('clientId')) {
|
||||
if (!Object.prototype.hasOwnProperty.call(parseWebsocket, 'clientId')) {
|
||||
Client.pushError(
|
||||
parseWebsocket,
|
||||
2,
|
||||
@@ -699,7 +702,7 @@ class ParseLiveQueryServer {
|
||||
notifyClient: boolean = true
|
||||
): any {
|
||||
// If we can not find this client, return error to client
|
||||
if (!parseWebsocket.hasOwnProperty('clientId')) {
|
||||
if (!Object.prototype.hasOwnProperty.call(parseWebsocket, 'clientId')) {
|
||||
Client.pushError(
|
||||
parseWebsocket,
|
||||
2,
|
||||
|
||||
@@ -13,7 +13,7 @@ var Parse = require('parse/node');
|
||||
* Convert $or queries into an array of where conditions
|
||||
*/
|
||||
function flattenOrQueries(where) {
|
||||
if (!where.hasOwnProperty('$or')) {
|
||||
if (!Object.prototype.hasOwnProperty.call(where, '$or')) {
|
||||
return where;
|
||||
}
|
||||
var accum = [];
|
||||
|
||||
@@ -356,12 +356,12 @@ function addParseCloud() {
|
||||
|
||||
function injectDefaults(options: ParseServerOptions) {
|
||||
Object.keys(defaults).forEach(key => {
|
||||
if (!options.hasOwnProperty(key)) {
|
||||
if (!Object.prototype.hasOwnProperty.call(options, key)) {
|
||||
options[key] = defaults[key];
|
||||
}
|
||||
});
|
||||
|
||||
if (!options.hasOwnProperty('serverURL')) {
|
||||
if (!Object.prototype.hasOwnProperty.call(options, 'serverURL')) {
|
||||
options.serverURL = `http://localhost:${options.port}${options.mountPath}`;
|
||||
}
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ export function validatePushType(where = {}, validPushTypes = []) {
|
||||
|
||||
export function applyDeviceTokenExists(where) {
|
||||
where = deepcopy(where);
|
||||
if (!where.hasOwnProperty('deviceToken')) {
|
||||
if (!Object.prototype.hasOwnProperty.call(where, 'deviceToken')) {
|
||||
where['deviceToken'] = { $exists: true };
|
||||
}
|
||||
return where;
|
||||
|
||||
@@ -71,7 +71,7 @@ function RestQuery(
|
||||
|
||||
// If we have keys, we probably want to force some includes (n-1 level)
|
||||
// See issue: https://github.com/parse-community/parse-server/issues/3185
|
||||
if (restOptions.hasOwnProperty('keys')) {
|
||||
if (Object.prototype.hasOwnProperty.call(restOptions, 'keys')) {
|
||||
const keysForInclude = restOptions.keys
|
||||
.split(',')
|
||||
.filter(key => {
|
||||
|
||||
@@ -1711,7 +1711,7 @@ RestWrite.prototype._updateResponseWithData = function(response, data) {
|
||||
this.storage.fieldsChangedByTrigger.forEach(fieldName => {
|
||||
const dataValue = data[fieldName];
|
||||
|
||||
if (!response.hasOwnProperty(fieldName)) {
|
||||
if (!Object.prototype.hasOwnProperty.call(response, fieldName)) {
|
||||
response[fieldName] = dataValue;
|
||||
}
|
||||
|
||||
|
||||
@@ -122,13 +122,13 @@ export class AggregateRouter extends ClassesRouter {
|
||||
);
|
||||
}
|
||||
if (stageName === 'group') {
|
||||
if (stage[stageName].hasOwnProperty('_id')) {
|
||||
if (Object.prototype.hasOwnProperty.call(stage[stageName], '_id')) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_QUERY,
|
||||
`Invalid parameter for query: group. Please use objectId instead of _id`
|
||||
);
|
||||
}
|
||||
if (!stage[stageName].hasOwnProperty('objectId')) {
|
||||
if (!Object.prototype.hasOwnProperty.call(stage[stageName], 'objectId')) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.INVALID_QUERY,
|
||||
`Invalid parameter for query: group. objectId is required`
|
||||
|
||||
@@ -20,7 +20,7 @@ export class UsersRouter extends ClassesRouter {
|
||||
*/
|
||||
static removeHiddenProperties(obj) {
|
||||
for (var key in obj) {
|
||||
if (obj.hasOwnProperty(key)) {
|
||||
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||
// Regexp comes from Parse.Object.prototype.validate
|
||||
if (key !== '__type' && !/^[A-Za-z][0-9A-Za-z_]*$/.test(key)) {
|
||||
delete obj[key];
|
||||
|
||||
@@ -148,7 +148,7 @@ export function pushStatusHandler(config, existingObjectId) {
|
||||
const now = new Date();
|
||||
let pushTime = now.toISOString();
|
||||
let status = 'pending';
|
||||
if (body.hasOwnProperty('push_time')) {
|
||||
if (Object.prototype.hasOwnProperty.call(body, 'push_time')) {
|
||||
if (config.hasPushScheduledSupport) {
|
||||
pushTime = body.push_time;
|
||||
status = 'scheduled';
|
||||
|
||||
@@ -102,7 +102,7 @@ function parseConfigFile(program) {
|
||||
|
||||
Command.prototype.setValuesIfNeeded = function(options) {
|
||||
Object.keys(options).forEach(key => {
|
||||
if (!this.hasOwnProperty(key)) {
|
||||
if (!Object.prototype.hasOwnProperty.call(this, key)) {
|
||||
this[key] = options[key];
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2,7 +2,10 @@ import { Parse } from 'parse/node';
|
||||
import * as triggers from '../triggers';
|
||||
|
||||
function isParseObjectConstructor(object) {
|
||||
return typeof object === 'function' && object.hasOwnProperty('className');
|
||||
return (
|
||||
typeof object === 'function' &&
|
||||
Object.prototype.hasOwnProperty.call(object, 'className')
|
||||
);
|
||||
}
|
||||
|
||||
function getClassName(parseClass) {
|
||||
|
||||
@@ -19,7 +19,7 @@ const { verbose, level } = (() => {
|
||||
const DefinitionDefaults = Object.keys(ParseServerOptions).reduce(
|
||||
(memo, key) => {
|
||||
const def = ParseServerOptions[key];
|
||||
if (def.hasOwnProperty('default')) {
|
||||
if (Object.prototype.hasOwnProperty.call(def, 'default')) {
|
||||
memo[key] = def.default;
|
||||
}
|
||||
return memo;
|
||||
|
||||
Reference in New Issue
Block a user