Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

Commit f612723

Browse files
authored
refactor(cli): replace dynamic function call eval with regex match for datasource url (#637)
* refactor(cli): replace dynamic function call eval with regex match for datasource url * fix(proxy): improve regex for env() function call matching
1 parent 895b8f1 commit f612723

1 file changed

Lines changed: 7 additions & 15 deletions

File tree

packages/cli/src/actions/proxy.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,17 @@ export async function run(options: Options) {
8787
}
8888

8989
function evaluateUrl(value: string): string {
90-
// Create env helper function
91-
const env = (varName: string) => {
92-
const envValue = process.env[varName];
90+
// Check if it's an env() function call
91+
const envMatch = value.trim().match(/^env\s*\(\s*['"]([^'"]+)['"]\s*\)$/);
92+
if (envMatch) {
93+
const varName = envMatch[1];
94+
const envValue = process.env[varName!];
9395
if (!envValue) {
9496
throw new CliError(`Environment variable ${varName} is not set`);
9597
}
9698
return envValue;
97-
};
98-
99-
try {
100-
// Use Function constructor to evaluate the url value
101-
const urlFn = new Function('env', `return ${value}`);
102-
const url = urlFn(env);
103-
return url;
104-
} catch (err) {
105-
if (err instanceof CliError) {
106-
throw err;
107-
}
108-
throw new CliError('Could not evaluate datasource url from schema, you could provide it via -d option.');
99+
} else {
100+
return value;
109101
}
110102
}
111103

0 commit comments

Comments
 (0)