Skip to content

Fix form urlencoded request bodies#20

Merged
abnegate merged 1 commit intoutopia-php:mainfrom
ChiragAgg5k:fix/form-urlencoded-body-encoding
Apr 29, 2026
Merged

Fix form urlencoded request bodies#20
abnegate merged 1 commit intoutopia-php:mainfrom
ChiragAgg5k:fix/form-urlencoded-body-encoding

Conversation

@ChiragAgg5k
Copy link
Copy Markdown
Member

Summary

  • encode application/x-www-form-urlencoded array bodies with http_build_query() before sending
  • keep multipart bodies as flattened arrays for file/form uploads
  • add a regression test that asserts the raw form-urlencoded request body

Context

CURLOPT_POSTFIELDS treats an array body differently from a URL-encoded string. OAuth-style endpoints that expect application/x-www-form-urlencoded payloads require a raw query-string body, for example grant_type=client_credentials&client_id=....

Test Plan

  • php -d error_reporting='E_ALL & ~E_DEPRECATED' vendor/bin/phpunit --filter testFormUrlencodedArrayBody
  • php -d error_reporting='E_ALL & ~E_DEPRECATED' vendor/bin/phpunit tests/ClientTest.php
  • vendor/bin/pint --test --config pint.json src/Client.php tests/ClientTest.php

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 28, 2026

Greptile Summary

This PR fixes application/x-www-form-urlencoded request bodies by calling http_build_query() instead of flatten(), producing the raw query-string format that OAuth and similar endpoints require. Multipart form-data bodies continue to use flatten() as before.

Confidence Score: 5/5

Safe to merge — one-line logic fix with a targeted regression test and no side-effects on other content types.

No P0 or P1 issues found. The change is minimal, correctly scoped, and the new test validates the exact wire format. Multipart handling is unchanged.

No files require special attention.

Important Files Changed

Filename Overview
src/Client.php Splits the single match arm for form-urlencoded and multipart into two: http_build_query() for urlencoded bodies, flatten() for multipart. Change is minimal, correct, and well-scoped.
tests/ClientTest.php Adds regression test for form-urlencoded array body, asserting the raw query-string sent to the test server matches the expected RFC 1738-encoded output. Minor concern: the hardcoded expected string ties the test to PHP's default bracket-notation array encoding.

Reviews (2): Last reviewed commit: "Fix form urlencoded request bodies" | Re-trigger Greptile

Comment thread src/Client.php Outdated
@ChiragAgg5k ChiragAgg5k force-pushed the fix/form-urlencoded-body-encoding branch from 9eb3afc to b988865 Compare April 28, 2026 14:24
@abnegate abnegate merged commit 77b84ac into utopia-php:main Apr 29, 2026
4 checks passed
@ChiragAgg5k ChiragAgg5k deleted the fix/form-urlencoded-body-encoding branch April 29, 2026 02:29
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.

3 participants