From 6e5b9f0e533ca1ef4c62396adcfcc4c7427e5933 Mon Sep 17 00:00:00 2001 From: Hardik Kaurani Date: Sat, 7 Nov 2026 11:51:59 +0530 Subject: [PATCH 1/4] fix(serialization): support content-type parameters in FormParseNodeFactory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Strip MIME parameters and surrounding whitespace from the content-type argument before comparing against the valid content type in FormParseNodeFactory.get_root_parse_node, aligning with RFC 2045 §5.1. Signed-off-by: Hardik Kaurani --- .../form/kiota_serialization_form/form_parse_node_factory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/serialization/form/kiota_serialization_form/form_parse_node_factory.py b/packages/serialization/form/kiota_serialization_form/form_parse_node_factory.py index 750a8937..2963b4aa 100644 --- a/packages/serialization/form/kiota_serialization_form/form_parse_node_factory.py +++ b/packages/serialization/form/kiota_serialization_form/form_parse_node_factory.py @@ -25,7 +25,7 @@ def get_root_parse_node(self, content_type: str, content: bytes) -> ParseNode: if not content_type: raise TypeError("Content Type cannot be null") valid_content_type = self.get_valid_content_type() - if valid_content_type.casefold() != content_type.casefold(): + if valid_content_type.casefold() != content_type.split(";")[0].strip().casefold(): raise TypeError(f"Expected {valid_content_type} as content type") if not content: From a73b83787ef6c8bdcdec8b1d556e18d58346cfb9 Mon Sep 17 00:00:00 2001 From: Hardik Kaurani Date: Sat, 7 Nov 2026 11:52:44 +0530 Subject: [PATCH 2/4] test(serialization): add regression tests for FormParseNodeFactory content-type parameters Add parameterized tests verifying that FormParseNodeFactory properly accepts content types with MIME parameters and case variations while continuing to reject delimiter-only and invalid content types. Signed-off-by: Hardik Kaurani --- .../unit/test_form_parse_node_factory.py | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/packages/serialization/form/tests/unit/test_form_parse_node_factory.py b/packages/serialization/form/tests/unit/test_form_parse_node_factory.py index 2e05e104..f3e6f9b7 100644 --- a/packages/serialization/form/tests/unit/test_form_parse_node_factory.py +++ b/packages/serialization/form/tests/unit/test_form_parse_node_factory.py @@ -45,4 +45,39 @@ def test_get_root_parse_node_empty_form(): def test_get_valid_content_type(): factory = FormParseNodeFactory() content_type = factory.get_valid_content_type() - assert content_type == FORM_CONTENT_TYPE \ No newline at end of file + assert content_type == FORM_CONTENT_TYPE + + +@pytest.mark.parametrize( + "content_type", + [ + "application/x-www-form-urlencoded; charset=utf-8", + "application/x-www-form-urlencoded; charset=UTF-8", + "application/x-www-form-urlencoded ; charset=utf-8", + "APPLICATION/X-WWW-FORM-URLENCODED", + "APPLICATION/X-WWW-FORM-URLENCODED; CHARSET=UTF-8", + "Application/x-www-form-urlencoded; charset=utf-8", + ], +) +def test_get_root_parse_node_with_parameters_and_case_variants(sample_form_string, content_type): + factory = FormParseNodeFactory() + sample_form_string_bytes = sample_form_string.encode('utf-8') + root = factory.get_root_parse_node(content_type, sample_form_string_bytes) + assert isinstance(root, FormParseNode) + + +@pytest.mark.parametrize( + "content_type", + [ + ";", + ";;", + "; charset=utf-8", + " ; charset=utf-8", + ], +) +def test_get_root_parse_node_delimiter_only(sample_form_string, content_type): + with pytest.raises(TypeError) as e_info: + factory = FormParseNodeFactory() + sample_form_string_bytes = sample_form_string.encode('utf-8') + factory.get_root_parse_node(content_type, sample_form_string_bytes) + assert str(e_info.value) == f"Expected {FORM_CONTENT_TYPE} as content type" From 587a66d519d2dbf582da81f06fabe7547df0e493 Mon Sep 17 00:00:00 2001 From: Hardik Kaurani Date: Sat, 7 Nov 2026 11:53:24 +0530 Subject: [PATCH 3/4] fix(serialization): support content-type parameters in FormSerializationWriterFactory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Strip MIME parameters and surrounding whitespace from the content-type argument before comparing against the valid content type in FormSerializationWriterFactory.get_serialization_writer, aligning with RFC 2045 §5.1. Signed-off-by: Hardik Kaurani --- .../form_serialization_writer_factory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/serialization/form/kiota_serialization_form/form_serialization_writer_factory.py b/packages/serialization/form/kiota_serialization_form/form_serialization_writer_factory.py index 3ae51fcf..dd4ded6e 100644 --- a/packages/serialization/form/kiota_serialization_form/form_serialization_writer_factory.py +++ b/packages/serialization/form/kiota_serialization_form/form_serialization_writer_factory.py @@ -24,7 +24,7 @@ def get_serialization_writer(self, content_type: str) -> SerializationWriter: if not content_type: raise TypeError("Content Type cannot be null") valid_content_type = self.get_valid_content_type() - if valid_content_type.casefold() != content_type.casefold(): + if valid_content_type.casefold() != content_type.split(";")[0].strip().casefold(): raise TypeError(f"Expected {valid_content_type} as content type") return FormSerializationWriter() From 197a7217343c5a2233704b3d2020d1599f9cef86 Mon Sep 17 00:00:00 2001 From: Hardik Kaurani Date: Sat, 7 Nov 2026 11:54:27 +0530 Subject: [PATCH 4/4] test(serialization): add regression tests for FormSerializationWriterFactory content-type parameters Add parameterized tests verifying that FormSerializationWriterFactory properly accepts content types with MIME parameters and case variations while continuing to reject delimiter-only and invalid content types. Signed-off-by: Hardik Kaurani --- .../test_form_serialization_writer_factory.py | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/packages/serialization/form/tests/unit/test_form_serialization_writer_factory.py b/packages/serialization/form/tests/unit/test_form_serialization_writer_factory.py index 4ecf4126..a67d17a0 100644 --- a/packages/serialization/form/tests/unit/test_form_serialization_writer_factory.py +++ b/packages/serialization/form/tests/unit/test_form_serialization_writer_factory.py @@ -29,4 +29,37 @@ def test_get_serialization_writer_unsupported_content_type(): def test_get_valid_content_type(): factory = FormSerializationWriterFactory() content_type = factory.get_valid_content_type() - assert content_type == FORM_CONTENT_TYPE \ No newline at end of file + assert content_type == FORM_CONTENT_TYPE + + +@pytest.mark.parametrize( + "content_type", + [ + "application/x-www-form-urlencoded; charset=utf-8", + "application/x-www-form-urlencoded; charset=UTF-8", + "application/x-www-form-urlencoded ; charset=utf-8", + "APPLICATION/X-WWW-FORM-URLENCODED", + "APPLICATION/X-WWW-FORM-URLENCODED; CHARSET=UTF-8", + "Application/x-www-form-urlencoded; charset=utf-8", + ], +) +def test_get_serialization_writer_with_parameters_and_case_variants(content_type): + factory = FormSerializationWriterFactory() + writer = factory.get_serialization_writer(content_type) + assert isinstance(writer, FormSerializationWriter) + + +@pytest.mark.parametrize( + "content_type", + [ + ";", + ";;", + "; charset=utf-8", + " ; charset=utf-8", + ], +) +def test_get_serialization_writer_delimiter_only(content_type): + with pytest.raises(TypeError) as e_info: + factory = FormSerializationWriterFactory() + factory.get_serialization_writer(content_type) + assert str(e_info.value) == f"Expected {FORM_CONTENT_TYPE} as content type"