Skip to content

Form serialization trims field names and merges distinct fields #892

Open

Description

FormSerializationWriter strips leading and trailing whitespace from field names before encoding them. As a result, distinct names such as field and field become the same form field.

This reproduces with unmodified main at 2150d1593be67ea5d5bd7040c4f99d6139e8d094, using only public APIs:

from urllib.parse import parse_qsl
from kiota_serialization_form.form_parse_node import FormParseNode
from kiota_serialization_form.form_serialization_writer import FormSerializationWriter

writer = FormSerializationWriter()
writer.write_str_value("field", "first")
writer.write_str_value(" field ", "second")
content = writer.get_serialized_content().decode("utf-8")
print(content)
print(parse_qsl(content))
print(FormParseNode(content).get_child_node(" field "))

Actual:

field=first&field=second
[('field', 'first'), ('field', 'second')]
None

Expected: field=first&+field+=second, preserving both names. The form serialization algorithm percent-encodes the original name and value. It does not trim the name.

The same trimming occurs when writing an object under a key and when writing a non-parsable object. Names containing only whitespace become empty names. This affects callers whose form properties or additional-data keys contain surrounding whitespace; I have not verified a downstream production incident.

PR #791 fixed whitespace in values and explicitly left key normalization unchanged. This report concerns names. Empty/absent keys and values are outside the proposed change.

Verified locally on Windows with CPython 3.13.7. Regression cases should preserve ASCII and Unicode whitespace in names, distinguish padded names from their unpadded counterparts, and cover all three writer paths.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      Needs Triage 🔍

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions