7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.
TypeScript
fix(key-parser): strip quotes from .env values that carry an inline comment (#609)
bosenstrong33545ca98c90
diff --git a/server/src/__tests__/lib/key-parser.test.ts b/server/src/__tests__/lib/key-parser.test.tsindex e9f70ef3..d1dc5711 100644--- a/server/src/__tests__/lib/key-parser.test.ts+++ b/server/src/__tests__/lib/key-parser.test.ts@@ -21,6 +21,19 @@ describe('key parser', () => {]);});+ it('unquotes dotenv values that carry an inline comment', () => {+ expect(parseDotEnv('GOOGLE_API_KEY="ai-test" # primary\nGROQ_API_KEY=\'gsk-test\' # backup')).toEqual([+ { key: 'GOOGLE_API_KEY', value: 'ai-test' },+ { key: 'GROQ_API_KEY', value: 'gsk-test' },+ ]);+ });++ it('keeps a # that is inside the quotes', () => {+ expect(parseDotEnv('NVIDIA_API_KEY="nv # test"')).toEqual([+ { key: 'NVIDIA_API_KEY', value: 'nv # test' },+ ]);+ });+it('parses flat JSON string values', () => {expect(parseJson(JSON.stringify({ MISTRAL_API_KEY: 'mist-test', PORT: 3001 }))).toEqual([{ key: 'MISTRAL_API_KEY', value: 'mist-test' },diff --git a/server/src/lib/key-parser.ts b/server/src/lib/key-parser.tsindex 634ba65e..b19701f2 100644--- a/server/src/lib/key-parser.ts+++ b/server/src/lib/key-parser.ts@@ -94,11 +94,15 @@ export function parseDotEnv(content: string): Array<{ key: string; value: stringconst key = line.slice(0, eqIndex).trim();let value = line.slice(eqIndex + 1).trimStart();- const doubleQuoted = value.startsWith('"') && value.endsWith('"');- const singleQuoted = value.startsWith("'") && value.endsWith("'");-- if (doubleQuoted || singleQuoted) {- value = value.slice(1, -1);+ // A quoted value ends at its closing quote; whatever follows is an inline+ // comment, not part of the credential. Matching on endsWith instead meant+ // `KEY="secret" # note` failed the quoted test, took the unquoted branch,+ // and imported the key with its quote characters still attached.+ const quote = value.startsWith('"') || value.startsWith("'") ? value[0] : '';+ const closeIndex = quote ? value.indexOf(quote, 1) : -1;++ if (closeIndex !== -1) {+ value = value.slice(1, closeIndex);} else {const commentIndex = value.indexOf(' #');if (commentIndex !== -1) value = value.slice(0, commentIndex);