Skip to content

Commit

Permalink
check hasOwnProperty when using for..in (#2132)
Browse files Browse the repository at this point in the history
check hasOwnProperty when using for..in
  • Loading branch information
xavdid-stripe authored Jul 9, 2024
1 parent 3908aca commit f5e86aa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = {
'func-style': ['error', 'declaration', {allowArrowFunctions: true}],
'generator-star-spacing': 'error',
'global-require': 'off',
'guard-for-in': 'off',
'guard-for-in': 'error',
'handle-callback-err': 'off',
'id-blacklist': 'error',
'id-length': 'off',
Expand Down
3 changes: 3 additions & 0 deletions src/ResourceNamespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ function ResourceNamespace(
>
): void {
for (const name in resources) {
if (!Object.prototype.hasOwnProperty.call(resources, name)) {
continue;
}
const camelCaseName = name[0].toLowerCase() + name.substring(1);

const resource = new resources[name](stripe);
Expand Down
6 changes: 5 additions & 1 deletion src/multipart.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
MultipartRequestData,
RequestData,
RequestHeaders,
StripeResourceObject,
RequestData,
} from './Types.js';
import {flattenAndStringify, stringifyRequestData} from './utils.js';

Expand Down Expand Up @@ -46,6 +46,10 @@ const multipartDataGenerator = (
const flattenedData = flattenAndStringify(data);

for (const k in flattenedData) {
if (!Object.prototype.hasOwnProperty.call(flattenedData, k)) {
continue;
}

const v = flattenedData[k];
push(`--${segno}`);
if (Object.prototype.hasOwnProperty.call(v, 'data')) {
Expand Down
21 changes: 14 additions & 7 deletions src/stripe.core.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import * as _Error from './Error.js';
import {RequestSender} from './RequestSender.js';
import {StripeResource} from './StripeResource.js';
import {AppInfo, StripeObject, UserProvidedConfig} from './Types.js';
import {WebhookObject, createWebhooks} from './Webhooks.js';
import * as apiVersion from './apiVersion.js';
import * as resources from './resources.js';
import {CryptoProvider} from './crypto/CryptoProvider.js';
import {HttpClient, HttpClientResponse} from './net/HttpClient.js';
import {PlatformFunctions} from './platform/PlatformFunctions.js';
import * as resources from './resources.js';
import {
determineProcessUserAgentProperties,
pascalToCamelCase,
validateInteger,
} from './utils.js';
import {CryptoProvider} from './crypto/CryptoProvider.js';
import {PlatformFunctions} from './platform/PlatformFunctions.js';
import {RequestSender} from './RequestSender.js';
import {StripeResource} from './StripeResource.js';
import {WebhookObject, createWebhooks} from './Webhooks.js';
import {StripeObject, AppInfo, UserProvidedConfig} from './Types.js';

const DEFAULT_HOST = 'api.stripe.com';
const DEFAULT_PORT = '443';
Expand Down Expand Up @@ -363,6 +363,9 @@ export function createStripe(
this._platformFunctions.getUname().then((uname: string | null) => {
const userAgent: Record<string, string> = {};
for (const field in seed) {
if (!Object.prototype.hasOwnProperty.call(seed, field)) {
continue;
}
userAgent[field] = encodeURIComponent(seed[field] ?? 'null');
}

Expand Down Expand Up @@ -417,6 +420,10 @@ export function createStripe(
*/
_prepResources(): void {
for (const name in resources) {
if (!Object.prototype.hasOwnProperty.call(resources, name)) {
continue;
}

// @ts-ignore
this[pascalToCamelCase(name)] = new resources[name](this);
}
Expand Down

0 comments on commit f5e86aa

Please sign in to comment.