Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Fix: Parser improvements and lint fixes

Daniel Hougaard1aee50a7518a
diff --git a/frontend/src/helpers/parseEnvVar.ts b/frontend/src/helpers/parseEnvVar.ts
index 20e09a16fb..27640b515c 100644
--- a/frontend/src/helpers/parseEnvVar.ts
+++ b/frontend/src/helpers/parseEnvVar.ts
@@ -1,26 +1,14 @@
/** Extracts the key and value from a passed in env string based on the provided delimiters. */
export const getKeyValue = (pastedContent: string, delimiters: string[]) => {
- let splitIndex = -1
- let key = ""
- let value = ""
+ const foundDelimiter = delimiters.find((delimiter) => pastedContent.includes(delimiter));
- for (const delimiter of delimiters) {
- const idx = pastedContent.indexOf(delimiter)
-
- if (idx !== -1) {
- splitIndex = idx
- break;
- }
- }
-
- // if only key is pasted
- if (splitIndex === -1) {
- key = pastedContent.trim()
- return { key, value: "" }
+ if (!foundDelimiter) {
+ return { key: pastedContent.trim(), value: "" };
}
- key = pastedContent.slice(0, splitIndex).trim()
- value = pastedContent.slice(splitIndex + 1).trim()
-
- return { key, value }
+ const [key, value] = pastedContent.split(foundDelimiter);
+ return {
+ key: key.trim(),
+ value: (value ?? "").trim()
+ };
};