vercel icon indicating copy to clipboard operation
vercel copied to clipboard

`vercel env pull` cannot properly handle value that contains `"`

Open cm-ayf opened this issue 1 year ago • 1 comments

vercel env pull cannot properly handle value that contains ". The problematic code is here: https://github.com/vercel/vercel/blob/4111fbaa89348d0b803059de9b647c3ed3788bc4/packages/cli/src/commands/env/pull.ts#L136-L143

I have some variable that contains serialized JSON string (that contains double-quoted strings) and I expect vercel env pull to use ' instead of ".

However, reading the implementation of dotenv, I have found that if both \n and " exists in the value, there is no method to escape them.

cm-ayf avatar Mar 12 '24 02:03 cm-ayf

@vercel-team this is a real issue because prevents any JSON from working!

This is my tiny workaround, but it does not work in a general purpose way.

import * as readline from 'node:readline'

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false,
})

rl.on('line', (line) => {
  // Replace double quotes with single quotes, but only when they're part of the value
  const processed = line.replace(/^(.*)="(.*)"$/g, "$1='$2'")
  console.log(processed)
})

rl.on('close', () => {
  process.exit(0)
})

tonyxiao avatar Feb 27 '25 16:02 tonyxiao