Skip to content

Commit 389456e

Browse files
authored
fix(envvars): fix split for pasting envvars with query params (#1156)
1 parent c720f23 commit 389456e

File tree

1 file changed

+42
-7
lines changed
  • apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/settings-modal/components/environment

1 file changed

+42
-7
lines changed

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/settings-modal/components/environment/environment.tsx

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,27 @@ export function EnvironmentVariables({
161161
const inputType = (e.target as HTMLInputElement).getAttribute('data-input-type') as
162162
| 'key'
163163
| 'value'
164-
const containsKeyValuePair = text.includes('=')
165164

166-
if (inputType && !containsKeyValuePair) {
167-
handleSingleValuePaste(text, index, inputType)
168-
return
165+
// If we're in a specific input field, check if this looks like environment variable key-value pairs
166+
if (inputType) {
167+
// Check if this looks like valid environment variable key-value pairs
168+
const hasValidEnvVarPattern = lines.some((line) => {
169+
const equalIndex = line.indexOf('=')
170+
if (equalIndex === -1 || equalIndex === 0) return false
171+
172+
const potentialKey = line.substring(0, equalIndex).trim()
173+
const envVarPattern = /^[A-Za-z_][A-Za-z0-9_]*$/
174+
return envVarPattern.test(potentialKey)
175+
})
176+
177+
// If it doesn't look like env vars, treat as single value paste
178+
if (!hasValidEnvVarPattern) {
179+
handleSingleValuePaste(text, index, inputType)
180+
return
181+
}
169182
}
170183

184+
// Try to parse as key-value pairs
171185
handleKeyValuePaste(lines)
172186
}
173187

@@ -180,14 +194,35 @@ export function EnvironmentVariables({
180194
const handleKeyValuePaste = (lines: string[]) => {
181195
const parsedVars = lines
182196
.map((line) => {
183-
const [key, ...valueParts] = line.split('=')
184-
const value = valueParts.join('=').trim()
197+
// Only split on = if it looks like a proper environment variable (key=value format)
198+
const equalIndex = line.indexOf('=')
199+
200+
// If no = found or = is at the beginning, skip this line
201+
if (equalIndex === -1 || equalIndex === 0) {
202+
return null
203+
}
204+
205+
const potentialKey = line.substring(0, equalIndex).trim()
206+
207+
// Check if the potential key looks like an environment variable name
208+
// Should be letters, numbers, underscores, and not contain spaces, URLs, etc.
209+
const envVarPattern = /^[A-Za-z_][A-Za-z0-9_]*$/
210+
211+
// If it doesn't look like an env var name, skip this line
212+
if (!envVarPattern.test(potentialKey)) {
213+
return null
214+
}
215+
216+
const key = potentialKey
217+
const value = line.substring(equalIndex + 1).trim()
218+
185219
return {
186-
key: key.trim(),
220+
key,
187221
value,
188222
id: Date.now() + Math.random(),
189223
}
190224
})
225+
.filter((parsed): parsed is NonNullable<typeof parsed> => parsed !== null)
191226
.filter(({ key, value }) => key && value)
192227

193228
if (parsedVars.length > 0) {

0 commit comments

Comments
 (0)