Skip to content

fix issue where auth:export doesn't escape double quotes for CSV format#10563

Merged
joehan merged 6 commits into
mainfrom
aalej_fix-3484
May 27, 2026
Merged

fix issue where auth:export doesn't escape double quotes for CSV format#10563
joehan merged 6 commits into
mainfrom
aalej_fix-3484

Conversation

@aalej
Copy link
Copy Markdown
Contributor

@aalej aalej commented May 27, 2026

Description

Fixes #3484. from what I can tell, the issue was just double quotes ", since we wrap the entire string in double quotes, if the displayName has double quotes it would be escaped early

Scenarios Tested

Ran firebase auth:export --format csv --project PROJECT_ID users.csv and verified that user data is exported correctly

Sample Commands

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request fixes an issue where auth:export does not properly escape double quotes for the CSV format. It renames escapeComma to escapeCsv and updates it to handle both commas and double quotes (by doubling them and wrapping the field in quotes). A corresponding unit test has been added to src/accountExporter.spec.ts. The reviewer pointed out that fields containing line breaks (\n or \r) must also be enclosed in double quotes to prevent breaking the CSV structure, and provided a code suggestion to address this.

Comment thread src/accountExporter.ts
Comment on lines +46 to 53
function escapeCsv(str: string): string {
if (str.includes(",") || str.includes('"')) {
// Encapsulate the string with quotes if it contains a comma.
return `"${str}"`;
// Also escape any existing quotes by doubling them.
return `"${str.replace(/"/g, '""')}"`;
}
return str;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

In CSV format, fields containing line breaks (newlines like \n or \r) must also be enclosed in double quotes, just like fields containing commas or double quotes. If a user's display name contains a newline, not escaping it will break the CSV structure by introducing an unexpected new row. We should update escapeCsv to also check for \n and \r.

Suggested change
function escapeCsv(str: string): string {
if (str.includes(",") || str.includes('"')) {
// Encapsulate the string with quotes if it contains a comma.
return `"${str}"`;
// Also escape any existing quotes by doubling them.
return `"${str.replace(/"/g, '""')}"`;
}
return str;
}
function escapeCsv(str: string): string {
if (str.includes(",") || str.includes('"') || str.includes("\n") || str.includes("\r")) {
// Encapsulate the string with quotes if it contains a comma, quote, or newline.
// Also escape any existing quotes by doubling them.
return "\"" + str.replace(/"/g, '""') + "\"";
}
return str;
}

@aalej aalej requested a review from joehan May 27, 2026 16:44
@joehan joehan merged commit 7878e57 into main May 27, 2026
33 of 35 checks passed
@joehan joehan deleted the aalej_fix-3484 branch May 27, 2026 20:32
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.

Firebase Auth export doesn't escape characters for a proper CSV format

3 participants