Skip to content

fix: support encoding of special characters in path params for gen2 f…#780

Draft
IzaakGough wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
IzaakGough:fix/firestore-utf8-binary-header-decoding
Draft

fix: support encoding of special characters in path params for gen2 f…#780
IzaakGough wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
IzaakGough:fix/firestore-utf8-binary-header-decoding

Conversation

@IzaakGough

@IzaakGough IzaakGough commented Jul 16, 2026

Copy link
Copy Markdown

Fixes firebase/firebase-functions#1459

Node.js decodes HTTP header bytes as Latin-1 by default. When Firestore (and potentially other services) send non-ASCII document paths as raw UTF-8 bytes in binary-mode CloudEvent extension attributes, getBinaryCloudEventContext receives them already corrupted — e.g. Helvétios arrives as Helvétios.

This is the root cause of firebase/firebase-functions#1459, which has been open since 2023 and affects all Gen2 Firestore triggers with non-ASCII document IDs.

Fix

Re-decode each header value from binary to UTF-8 before setting it on the CloudEvent:

const val = req.header(name);
context[attributeName] = val ? Buffer.from(val, 'binary').toString('utf-8') : val;

ASCII values are unaffected (ASCII is identical in both encodings).

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.

Gen2: Encoding issue with special characters in path parameters

1 participant