Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correction of a problem where export to dotenv fails if the config value is operated with empty characters in the 1st gen of functions. #7368

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ytetsuro
Copy link

@ytetsuro ytetsuro commented Jun 24, 2024

Description

Correction of a problem where export to dotenv fails if the config value is operated with empty characters in the 1st gen of functions.

Scenarios Tested

TypeError: Cannot read properties of undefined (reading 'replace')
    at escape (/Users/yoshikawa/.nodebrew/node/v20.10.0/lib/node_modules/firebase-tools/lib/functions/runtimeConfigExport.js:128:14)
    at /Users/yoshikawa/.nodebrew/node/v20.10.0/lib/node_modules/firebase-tools/lib/functions/runtimeConfigExport.js:131:100
    at Array.map (<anonymous>)
    at Object.toDotenvFormat (/Users/yoshikawa/.nodebrew/node/v20.10.0/lib/node_modules/firebase-tools/lib/functions/runtimeConfigExport.js:131:24)
    at /Users/yoshikawa/.nodebrew/node/v20.10.0/lib/node_modules/firebase-tools/lib/commands/functions-config-export.js:110:56
    at Array.map (<anonymous>)
    at Command.actionFn (/Users/yoshikawa/.nodebrew/node/v20.10.0/lib/node_modules/firebase-tools/lib/commands/functions-config-export.js:110:28)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Sample Commands

@colerogers colerogers self-assigned this Jul 18, 2024
@@ -178,7 +178,7 @@ const CHARACTERS_TO_ESCAPE_SEQUENCES: Record<string, string> = {

function escape(s: string): string {
// Escape newlines, tabs, backslashes and quotes
return s.replace(/[\n\r\t\v\\"']/g, (ch) => CHARACTERS_TO_ESCAPE_SEQUENCES[ch]);
return (s || '').replace(/[\n\r\t\v\\"']/g, (ch) => CHARACTERS_TO_ESCAPE_SEQUENCES[ch]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the issue is that s is coming into this function as undefined from the env map. Let's change where this is actually being called below.

@@ -178,7 +178,7 @@ const CHARACTERS_TO_ESCAPE_SEQUENCES: Record<string, string> = {

function escape(s: string): string {
// Escape newlines, tabs, backslashes and quotes
return s.replace(/[\n\r\t\v\\"']/g, (ch) => CHARACTERS_TO_ESCAPE_SEQUENCES[ch]);
return (s || '').replace(/[\n\r\t\v\\"']/g, (ch) => CHARACTERS_TO_ESCAPE_SEQUENCES[ch]);
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On line 188, let's change it to something like

const lines = envs.map(({ newKey, value }) => `${newKey}="${value === undefined ? "" : escape(value)}"`);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants