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

Gen2: Encoding issue with special characters in path parameters #1459

Open
Llolow opened this issue Sep 6, 2023 · 8 comments
Open

Gen2: Encoding issue with special characters in path parameters #1459

Llolow opened this issue Sep 6, 2023 · 8 comments
Assignees

Comments

@Llolow
Copy link

Llolow commented Sep 6, 2023

Version info

node: v18.16.0
firebase-functions: v4.4.1
firebase-tools: v12.5.2
firebase-admin: v11.8.0

Steps to reproduce

This issue was not encountered in gen1, and special characters in path parameters were correctly encoded.

  • Deploy a Firebase Cloud Function Gen2 using a Firestore trigger as follows:
    import { log } from "firebase-functions/logger";
    import { onDocumentUpdated } from "firebase-functions/v2/firestore";
    
    export const testPlanet = onDocumentUpdated("planetes/{planeteId}", async (event) => {
      log(event.params.planeteId);
    });
  • 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.

Actual behavior

After deploying the Firebase Cloud Function Gen2, the planeteId value appears to be incorrectly encoded, resulting in a value like Helvétios becoming Helvétios or Électre becoming Ã�lectre.

Were you able to successfully deploy your functions?

Yes, the deployment was successful without any error messages.

@google-oss-bot
Copy link
Collaborator

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@taeold taeold self-assigned this Sep 13, 2023
@taeold
Copy link
Contributor

taeold commented 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
Copy link
Author

Llolow commented 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
Copy link
Contributor

taeold commented Oct 23, 2023

@Llolow Sorry for not responding sooner.

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:

const planetId = Buffer.from(event.params.planeteId, "binary").toString("utf-8")

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
Copy link

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
Copy link

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:

d = Buffer.from("SD�V", "binary").toString("utf-8")
'SDÅV'

Application of the suggested workaround in case the parameter is already in utf-8:

e = Buffer.from("SDÅV", "binary").toString("utf-8")
'SD�V'

@adamxi
Copy link

adamxi commented May 29, 2024

Hey, this is an issue for us as well.

If the document id in event.params doesn't 100% match that of the actual firestore document, then this must surely be a bug in the SDK?

@albertopq
Copy link

Same issue here. Definitely a bug if v1 and v2 behave differently.

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

No branches or pull requests

6 participants