Skip to content

Conversation

@etr
Copy link
Owner

@etr etr commented Jan 27, 2026

Summary

Fixes #268 - POST body keys without values at the end are not processed when using application/x-www-form-urlencoded content type.

This PR supersedes #269 with the requested changes:

  • Uses nullptr instead of NULL (style fix)
  • Adds test cases to verify the fix

The Problem

When POST data ends with a key that has an empty value (e.g., arg1=val1&arg2=), the final key-value pair was not being processed. This happened because MHD_destroy_post_processor was only called in the destructor, after the request handler had already executed.

The Fix

Move the MHD_destroy_post_processor call to finalize_answer() before the resource callback is invoked. This ensures any pending POST data is finalized before the handler accesses the arguments.

Test Plan

  • Added new test empty_arg_value_at_end with three cases:
    • arg1=val1&arg2= → correctly parses both args
    • arg1= → correctly parses as empty string
    • arg1=&arg2= → correctly parses both as empty strings
  • All existing tests pass
  • cpplint passes

etr added 2 commits January 27, 2026 13:41
Destroy post processor before invoking the callback to ensure pending
POST body keys with empty values are properly finalized. Without this,
POST data like "arg1=val1&arg2=" would fail to include arg2.

The fix moves MHD_destroy_post_processor call to finalize_answer()
before the resource callback is invoked, rather than waiting for
the modded_request destructor.

Added test cases verifying:
- arg1=val1&arg2= correctly parses both args
- arg1= correctly parses as empty string
- arg1=&arg2= correctly parses both as empty strings

This supersedes PR #269 with the requested code style changes.
rand_r is POSIX-specific and not available on Windows. Since this is
just a stress test where thread-safe randomness isn't critical, use
the portable rand() function instead.
@etr etr force-pushed the fix-post-empty-arg-value branch from 2e9a4fb to 3733f81 Compare January 27, 2026 21:45
@etr etr merged commit 8ed6340 into master Jan 27, 2026
38 checks passed
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.

[BUG] Final keys without values are not processed for POST body

2 participants