Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check hasOwnProperty when using for..in #2132

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
xavdid-stripe marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -193,8 +193,8 @@

Stripe.prototype = {
// Properties are set in the constructor above
_appInfo: undefined!,

Check warning on line 196 in src/stripe.core.ts

View workflow job for this annotation

GitHub Actions / Build

Forbidden non-null assertion
on: null!,

Check warning on line 197 in src/stripe.core.ts

View workflow job for this annotation

GitHub Actions / Build

Forbidden non-null assertion
off: null!,
once: null!,
VERSION: null!,
Expand Down Expand Up @@ -363,6 +363,9 @@
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 @@
*/
_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
Loading