trypost/tests/Feature/Api
Paulo Castellano 74e6d341ab
fix: sanitize invalid UTF-8 bytes in uploaded filenames (#265)
* fix: sanitize invalid UTF-8 bytes in uploaded filenames

A client-supplied filename containing a raw non-UTF-8 byte (e.g. 0x97,
a Windows-1252 em dash) crashed the media insert with an uncaught
QueryException: Postgres rejects invalid UTF-8 byte sequences outright
under UTF8 encoding. Centralized a sanitizeOriginalFilename() helper
in HasMedia and applied it to all three insert paths that store
original_filename: addMedia(), addMediaFromPath(), and
addMediaFromStoredPath() (the multipart cloud-upload registration
path) — so every upload entry point is covered, not just the one that
happened to crash in production.

Fixes Nightwatch issue #24.

* refactor: use mb_scrub() instead of the mb_convert_encoding same-encoding trick

mb_scrub() (PHP 8.1+) is the purpose-built function for scrubbing
invalid byte sequences — same behavior, clearer intent than the
convert-to-same-encoding workaround it replaces.

* test: cover addMediaFromStoredPath (previously untested, including sanitize fix)

addMediaFromStoredPath — the multipart cloud-upload registration path
— had zero test coverage before this PR, including for the invalid
UTF-8 filename fix applied to it. Added a basic happy-path test plus
the sanitize regression test, matching the coverage already added for
addMedia() and addMediaFromPath().

Verified the regression test actually catches the bug: reverted the
sanitize call for this one method locally, confirmed the test fails
with the exact Nightwatch #24 QueryException, then restored the fix.
2026-08-09 14:29:29 -03:00
..
ApiKeyApiTest.php Scope MCP OAuth tokens to user + workspace (#222) (#245) 2026-08-06 21:59:34 -03:00
DiscordChannelsApiTest.php Address PR review: stream MCP uploads and close listing gaps. 2026-07-24 22:00:07 -03:00
LabelApiTest.php feat: migrate custom API token implementation to Laravel Passport for authentication and token management 2026-05-03 18:38:17 -03:00
LoadWorkspaceFromTokenTest.php Scope MCP OAuth tokens to user + workspace (#222) (#245) 2026-08-06 21:59:34 -03:00
PinterestBoardsApiTest.php Clamp media byte caps to upload limits and surface truncated board lists. 2026-07-24 22:49:04 -03:00
PlatformApiTest.php Enforce carousel min slides in Generate and expose min_media_count on API/MCP. 2026-07-24 23:51:10 -03:00
PostApiPlatformMetaTest.php Add optional Pinterest pin title and destination link (#232) 2026-08-05 18:15:50 -03:00
PostApiTest.php fix: keep post drafts unscheduled by default (#209) 2026-08-01 17:39:18 -03:00
PostMediaApiTest.php fix(security): make SSRF private-network block configurable and guard the last user-URL fetches 2026-07-17 15:40:15 -03:00
SignatureApiTest.php feat: migrate custom API token implementation to Laravel Passport for authentication and token management 2026-05-03 18:38:17 -03:00
SocialAccountApiTest.php feat: migrate custom API token implementation to Laravel Passport for authentication and token management 2026-05-03 18:38:17 -03:00
UploadControllerTest.php fix: sanitize invalid UTF-8 bytes in uploaded filenames (#265) 2026-08-09 14:29:29 -03:00
WorkspaceApiTest.php feat: migrate custom API token implementation to Laravel Passport for authentication and token management 2026-05-03 18:38:17 -03:00