Skip to content

Fix utf8 encoding for payload#1039

Merged
Assem-Uber merged 3 commits intocadence-workflow:masterfrom
Assem-Uber:feature/15550/fix-payload-encoding-utf-8
Sep 26, 2025
Merged

Fix utf8 encoding for payload#1039
Assem-Uber merged 3 commits intocadence-workflow:masterfrom
Assem-Uber:feature/15550/fix-payload-encoding-utf-8

Conversation

@Assem-Uber
Copy link
Contributor

Summary
Decoding utf-8 payloads is broken since we are using atob for decoding the base64 strings created by grpc-loader for Byte data. This causes wrong value display for user added inputs.

Fixes #1011

Changes*

  • Create a util for decoding base64 to utf-8 strings.
  • Use this utility in all formatters that expects a base64 string.

Screenshots
Screenshot 2025-09-25 at 14 22 52

Signed-off-by: Assem Hafez <assem.hafez@uber.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes UTF-8 encoding issues when decoding base64 payloads by replacing the native atob function with a proper UTF-8 decoder. The change addresses broken display of user-added inputs containing non-ASCII characters.

  • Created a utility function formatBase64Payload that properly handles UTF-8 encoding using Node.js Buffer
  • Replaced all instances of atob with the new utility across workflow history event formatters and payload formatters
  • Added comprehensive tests covering various character sets including mixed languages, Cyrillic, Chinese, Arabic, Hebrew, and emojis

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/utils/data-formatters/format-base64-payload.ts New utility function for proper UTF-8 base64 decoding
src/utils/data-formatters/tests/format-base64-payload.test.ts Test suite covering various UTF-8 character encodings
src/utils/data-formatters/format-payload.ts Updated to use new UTF-8 decoder utility
src/utils/data-formatters/format-input-payload.ts Updated to use new UTF-8 decoder utility
src/utils/data-formatters/format-failure-details.ts Updated to use new UTF-8 decoder utility
src/utils/data-formatters/format-workflow-history-event/*.ts Multiple workflow event formatters updated to use new UTF-8 decoder for control fields

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

});

it('should decode "ЕГ" from known base64 encoding', () => {
const result = formatBase64Payload('0JXQkw==');
Copy link
Member

Choose a reason for hiding this comment

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

This case should be covered by the one above (same for "hello world")

Alternatively, you can have separate test cases for different scripts (Latin, Cyrillic, Arabic, etc)

@Assem-Uber Assem-Uber merged commit ca0567d into cadence-workflow:master Sep 26, 2025
4 checks passed
@Assem-Uber Assem-Uber deleted the feature/15550/fix-payload-encoding-utf-8 branch September 26, 2025 16:53
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.

Wrong encoding

3 participants