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

Prevent config.parse() output from being used as input #134

Merged
merged 2 commits into from
Jun 13, 2020
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 packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@walmartlabs/cookie-cutter-core",
"version": "1.3.0-beta.4",
"version": "1.3.0-beta.5",
"license": "Apache-2.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
13 changes: 12 additions & 1 deletion packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ export function parse<T>(TRoot: IClassType<T>, actual: any, base?: Partial<T>):
}
}

if (isSection(actual)) {
throw new Error(
"The value of `actual` has no enumerable properties. Make sure the object being " +
"passed is not the output of `config.parse<T>()` (i.e. does not have the '@section' decorator)."
);
}

const instance = new TRoot();
if (verifyIsSection(instance)) {
const config: T & ISection = new TRoot() as any;
Expand Down Expand Up @@ -303,8 +310,12 @@ interface ISection {
readonly __extensible?: boolean;
}

function isSection(obj: any): obj is ISection {
return obj && obj.__assignedProperties;
}

function verifyIsSection(obj: any): obj is ISection {
if (obj && obj.__assignedProperties) {
if (isSection(obj)) {
return true;
}

Expand Down