Commit d94f4ea8cbd for woocommerce

commit d94f4ea8cbd1a388c33c29c319b8b855f9459803
Author: Luigi Teschio <gigitux@gmail.com>
Date:   Fri Nov 20 16:50:39 2026 +0100

    Escape quotes in formula-prefixed values in Analytics CSV downloads (#71235)

    (cherry picked from commit 1788007b285897fca06b91cfc27b1be407cd52d1)

    Co-authored-by: Lourens Schep <lourensschep@gmail.com>

diff --git a/packages/js/csv-export/src/index.ts b/packages/js/csv-export/src/index.ts
index 6139f4750cc..c74b589a29c 100644
--- a/packages/js/csv-export/src/index.ts
+++ b/packages/js/csv-export/src/index.ts
@@ -38,7 +38,7 @@ function escapeCSVValue( value: string | number ) {
 			String.fromCharCode( 0x0d ), // carriage return
 		].includes( stringValue.charAt( 0 ) )
 	) {
-		stringValue = '"\'' + stringValue + '"';
+		stringValue = '"\'' + stringValue.replace( /"/g, '""' ) + '"';
 	} else if ( stringValue.match( /[,"\s]/ ) ) {
 		stringValue = '"' + stringValue.replace( /"/g, '""' ) + '"';
 	}
diff --git a/packages/js/csv-export/src/test/index.ts b/packages/js/csv-export/src/test/index.ts
index fb9b11aa493..5205e192b60 100644
--- a/packages/js/csv-export/src/test/index.ts
+++ b/packages/js/csv-export/src/test/index.ts
@@ -47,6 +47,11 @@ describe( 'generateCSVDataFromTable', () => {
 				input: String.fromCharCode( 0x0d ) + 'danger',
 				expected: `"'${ String.fromCharCode( 0x0d ) }danger"`,
 			},
+			// Embedded quotes must be doubled so they cannot end the escaped cell early.
+			{
+				input: '=1",=HYPERLINK("http://example.com"),"',
+				expected: `"'=1"",=HYPERLINK(""http://example.com""),"""`,
+			},

 			// The values below should not be escaped since they are pure numeric values.
 			{ input: 12, expected: '12' },