-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
49 additions
and
68 deletions.
There are no files selected for viewing
21 changes: 0 additions & 21 deletions
21
packages/insomnia/src/ui/components/codemirror/__tests__/should-indent-with-tabs.test.ts
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
packages/insomnia/src/ui/components/editors/__tests__/environment-editor.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/insomnia/src/ui/components/editors/environment-utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { NUNJUCKS_TEMPLATE_GLOBAL_PROPERTY_NAME } from '../../../templating'; | ||
|
||
// NeDB field names cannot begin with '$' or contain a period '.' | ||
// Docs: https://github.com/DeNA/nedb#inserting-documents | ||
const INVALID_NEDB_KEY_REGEX = /^\$|\./; | ||
|
||
export const ensureKeyIsValid = (key: string, isRoot: boolean): string | null => { | ||
if (key.match(INVALID_NEDB_KEY_REGEX)) { | ||
return `"${key}" cannot begin with '$' or contain a '.'`; | ||
} | ||
|
||
if (key === NUNJUCKS_TEMPLATE_GLOBAL_PROPERTY_NAME && isRoot) { | ||
return `"${NUNJUCKS_TEMPLATE_GLOBAL_PROPERTY_NAME}" is a reserved key`; | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
/** | ||
* Recursively check nested keys in and immediately return when an invalid key found | ||
*/ | ||
export function checkNestedKeys(obj: Record<string, any>, isRoot = true): string | null { | ||
for (const key in obj) { | ||
let result: string | null = null; | ||
|
||
// Check current key | ||
result = ensureKeyIsValid(key, isRoot); | ||
|
||
// Exit if necessary | ||
if (result) { | ||
return result; | ||
} | ||
|
||
// Check nested keys | ||
if (typeof obj[key] === 'object') { | ||
result = checkNestedKeys(obj[key], false); | ||
} | ||
|
||
// Exit if necessary | ||
if (result) { | ||
return result; | ||
} | ||
} | ||
|
||
return null; | ||
} |