Skip to content

fix(form): base64-decode bytes values on deserialization - #832

Merged
Vincent Biret (baywet) merged 1 commit into
microsoft:mainfrom
protonnegativo:fix/form-bytes-base64
Oct 27, 2026
Merged

Vincent Biret (baywet) merged 1 commit into
microsoft:mainfrom
protonnegativo:fix/form-bytes-base64

Conversation

@protonnegativo

Copy link
Copy Markdown
Contributor

Overview

FormSerializationWriter.write_bytes_value() writes bytes as base64, but FormParseNode.get_bytes_value() returned the base64 text encoded as UTF-8 instead of decoding it, so a value written by the form writer did not read back as the original bytes. This decodes it with base64.b64decode, the same change #646 made for JsonParseNode. TextParseNode already decodes.

Related Issue

Fixes #831

Notes

  • This changes what get_bytes_value() returns, as fix(json): base64-decode bytes values on deserialization #646 did for JSON. Code that worked around the bug by calling base64.b64decode() on the result (the existing test_get_bytes_value did that) would now decode twice.
  • get_collection_of_primitive_values(bytes) uses the same helper, so it now returns decoded values too.
  • A value that is not valid base64 now returns None through the existing except in _get_bytes_value. It used to come back as its raw UTF-8 bytes.
  • No CHANGELOG change, per CONTRIBUTING.

Testing Instructions

  • cd packages/serialization/form
  • pip install -r requirements-dev.txt
  • pytest: 121 passed. With only the parse node change reverted, test_get_bytes_value, test_get_bytes_value_round_trip, test_get_bytes_value_invalid_base64 and test_get_collection_of_bytes_values fail.
  • yapf -dr kiota_serialization_form, isort kiota_serialization_form, pylint kiota_serialization_form --disable=W --rcfile=.pylintrc and mypy kiota_serialization_form are clean.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The narrow fix restores writer-reader symmetry, with regression coverage for the affected behavior and no unresolved findings.

No open issues 🎉

What changed in this PR

Fixes #831 by making form byte deserialization decode base64, matching the form writer and the JSON fix in #646.

Changes:

  • Decode base64 values instead of returning their UTF-8 bytes.
  • Correct the existing assertion and add regression tests for round trips, malformed input, and byte collections.
File Description
packages/​serialization/​form/​tests/​unit/​test_form_parse_node.py Verifies decoded bytes and adds regression coverage.
packages/​serialization/​form/​kiota_serialization_form/​form_parse_node.py Uses base64.b64decode in the bytes helper.

Review effort: Balanced

@github-project-automation github-project-automation Bot moved this to In Progress 🚧 in Kiota Oct 27, 2026
@baywet

Copy link
Copy Markdown
Member

Dennys Kaluzny Pereira (@protonnegativo) would you mind signing the CLA (see the bot comment) please? This way we'll be able to merge the PR

@protonnegativo

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

FormSerializationWriter.write_bytes_value writes bytes as base64, but
FormParseNode.get_bytes_value returned the base64 text encoded as UTF-8
instead of decoding it, so a value written by the writer did not read
back as the original bytes.

Decode the value with base64.b64decode, as the JSON (microsoft#646) and text
parse nodes do.
Copilot AI balanced review requested due to automatic review settings October 27, 2026 18:48
@sonarqubecloud

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused fix restores writer-reader symmetry and includes targeted regression coverage, with no blocking issues identified.

No open issues 🎉

Review effort: Balanced

@baywet
Vincent Biret (baywet) merged commit 69a040a into microsoft:main Oct 27, 2026
69 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress 🚧 to Done ✔️ in Kiota Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

FormParseNode.get_bytes_value() does not base64-decode (asymmetric with write_bytes_value)

3 participants