You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Gen2: Encoding issue with special characters in path parameters #1459
Ensure that the planeteId document contains special characters such as "é", "è", "à", etc. Example: "Helvétios", "Électre".
Observe the planeteId value in the deployed function
Expected behavior
The planeteId value should be correctly encoded and displayed in UTF-8, preserving special characters such as "é", "è", "à", etc., in the deployed Firebase Cloud Function Gen2.
Hi @Llolow. I don't have a solution yet, but I wanted to share an update.
It looks like the issue you've found goes beyond Cloud Functions for Firebase, and I'm in conversations with other teams at GCP to find the underlying issue. Thanks for your patience.
I've learned since then that event.document will contains that's formatted as octal-encoded UTF-8 string. To retrieve the "actual" document path, then, you can convert the bytes as utf-8 string:
I would agree with you to think that this is pretty tricky. Let me try and see if we can come up with a way to do the conversion in the SDK itself so you don't have to bother with these kind of problems.
Hi @taeold ,
We were just hit by this too. It's definitely a regression when migrating from v1 to v2, and it ought to be noted in the migration document that you can no longer rely on the 'params' when using special characters (even non-ascii ansi characters like Å).
If we add a workaround like the above - how will that effect a possible future fix? Will the workaround then break?
Also: I definitely don't consider this to be a feature request, but a serious bug that affects real-life usage of Cloud Functions v2.
This issue affects us as well. I baked a solution with AI that overcomes the problem stated by @mortenbekditlevsen, while google doesn't come up with a patch. (This is major for non-english speakers, guys!)
function toUTF8<T extends string>(value: T): string {
return Buffer.from(value, "binary").toString("utf-8");
}
export function fixEncoding<T extends Record<string, any> & { params: Record<string, string> }, K extends keyof T>(
event: T,
props: K[]
): void {
// Fix encoding on all event params
for (const param of Object.keys(event.params)) {
event.params[param] = toUTF8(event.params[param]);
}
// Fix enconding on any specified event properties
for (const prop of props) {
const val = event[prop];
if (val) {
(event[prop] as string) = toUTF8(val);
}
}
}
And then inside the function, in the very beginning, I just call fixEncoding with the event object and any extra properties that I know can have encoding issues:
@cachefulton I have got a potential fix in for this which seems to work for all examples discussed in this issue. I have also tested it with some emojis and other cases such as Arabic, Mandarin etc.
Hi @adegruchy, thanks for pinging on this, sorry it has been inactive. I have started looking into this again to see if we can fix purely in the SDK. I will provide updates as soon as I have them.
Activity
google-oss-bot commentedon Sep 6, 2023
I found a few problems with this issue:
taeold commentedon Sep 18, 2023
Hi @Llolow. I don't have a solution yet, but I wanted to share an update.
It looks like the issue you've found goes beyond Cloud Functions for Firebase, and I'm in conversations with other teams at GCP to find the underlying issue. Thanks for your patience.
Llolow commentedon Sep 28, 2023
Hello @taeold, thanks for the answer.
I will use for the moment the fact than gen1 and gen2 functions can coexist
taeold commentedon Oct 23, 2023
@Llolow Sorry for not responding sooner.
I've learned since then that
event.documentwill contains that's formatted as octal-encoded UTF-8 string. To retrieve the "actual" document path, then, you can convert the bytes as utf-8 string:I would agree with you to think that this is pretty tricky. Let me try and see if we can come up with a way to do the conversion in the SDK itself so you don't have to bother with these kind of problems.
mortenbekditlevsen commentedon Dec 22, 2023
Hi @taeold ,
We were just hit by this too. It's definitely a regression when migrating from v1 to v2, and it ought to be noted in the migration document that you can no longer rely on the 'params' when using special characters (even non-ascii ansi characters like Å).
If we add a workaround like the above - how will that effect a possible future fix? Will the workaround then break?
Also: I definitely don't consider this to be a feature request, but a serious bug that affects real-life usage of Cloud Functions v2.
mortenbekditlevsen commentedon Dec 22, 2023
Hi again @taeold ,
In my own testing, the workaround you suggest can be 'dangerous' in case the underlying issue is suddenly fixed:
Taking the string "SDÅV" as an example:
Suggested workaround:
Application of the suggested workaround in case the parameter is already in utf-8:
adamxi commentedon May 29, 2024
Hey, this is an issue for us as well.
If the document id in
event.paramsdoesn't 100% match that of the actual firestore document, then this must surely be a bug in the SDK?albertopq commentedon Sep 4, 2024
Same issue here. Definitely a bug if v1 and v2 behave differently.
Padreco-lbr commentedon May 21, 2025
This issue affects us as well. I baked a solution with AI that overcomes the problem stated by @mortenbekditlevsen, while google doesn't come up with a patch. (This is major for non-english speakers, guys!)
It uses the iconv-lite library.
I did not test it extensively, just enough for my use cases.
adamxi commentedon May 22, 2025
I solved it like this:
And then inside the function, in the very beginning, I just call fixEncoding with the event object and any extra properties that I know can have encoding issues:
fixEncoding(event, ["ref"]);cachefulton commentedon May 27, 2026
Any update on this for fixing the underlying issue without us needing a work around? I am having this issue with emojis!
IzaakGough commentedon Jun 17, 2026
@cachefulton I have got a potential fix in for this which seems to work for all examples discussed in this issue. I have also tested it with some emojis and other cases such as Arabic, Mandarin etc.
I will provide updates here as soon as possible.
adegruchy commentedon Oct 20, 2026
Any progress on this? This is affecting our
onValueWrittenFirebase functions and we would love to drop the need for a workaround.IzaakGough commentedon Oct 22, 2026
Hi @adegruchy, thanks for pinging on this, sorry it has been inactive. I have started looking into this again to see if we can fix purely in the SDK. I will provide updates as soon as I have them.
adegruchy commentedon Oct 22, 2026
Thank you!