Commit 39a0718
Forms: Fix fatal error when field render value is an array (#48032)
* Fix fatal error in get_legacy_extra_values when field value is an array
Guard against array values being used as array keys in the
get_legacy_extra_values method. When a form field (e.g., email) receives
array POST data, get_render_value() returns an array which cannot be
used as a PHP array key, causing a TypeError fatal error.
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
* Enforce string values for single-value field types
For field types that should always be strings (email, name, url,
subject, textarea, ip), take the first element when array POST data
is submitted. Also use first-element fallback in get_legacy_extra_values
as a defensive guard for any pre-existing array values.
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
* Rewrite test to reproduce the fatal without test isolation dependency
Use direct Feedback_Field construction with array value for a url-type
field and v2 format storage, which works in isolation. The key is using
'submit' context — get_render_submit_value() returns the raw array,
unlike 'default' which implodes it.
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
* Add parameterized tests for all non-extra field types with array values
Test every field type in $non_extra_fields (email, name, url, subject,
textarea, ip) with array values across both submit and default contexts.
Also verify checkbox-multiple arrays are preserved in submit context
and imploded in default context.
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
* Strengthen test assertions to verify data correctness, not just no-crash
Assert that extra values contain expected field values (Comment text
field in parameterized tests, checkbox-multiple array in preservation
test), not just that the method returns an array.
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
* Fix changelog entry: add trailing period and broaden description to cover both fixed sites
Agent-Logs-Url: https://github.com/Automattic/jetpack/sessions/7b5b7414-2667-4535-9781-d5ef5ee74cac
Co-authored-by: enejb <[email protected]>
* Add test for legacy v1 checkbox-multiple array preservation
Legacy v1 format stores checkbox-multiple as JSON arrays with field
type 'basic'. Verify the full array survives the round-trip and is
not flattened by the reset() guard in get_legacy_extra_values().
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
* Simplify fatal error fix to minimal array handling
The type-aware unwrap logic added in e29b191 was broader than
necessary. The minimal fix for the fatal is to handle arrays in
sanitization; preserve arrays for all field types and let downstream
code handle them.
---------
Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: enejb <[email protected]>1 parent 495c63e commit 39a0718
3 files changed
Lines changed: 220 additions & 4 deletions
File tree
- projects/packages/forms
- changelog
- src/contact-form
- tests/php/contact-form
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
Lines changed: 14 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
649 | 649 | | |
650 | 650 | | |
651 | 651 | | |
652 | | - | |
| 652 | + | |
653 | 653 | | |
654 | | - | |
655 | | - | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
656 | 662 | | |
657 | 663 | | |
658 | 664 | | |
659 | 665 | | |
660 | 666 | | |
661 | 667 | | |
662 | 668 | | |
663 | | - | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
664 | 674 | | |
665 | 675 | | |
666 | 676 | | |
| |||
Lines changed: 202 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
296 | 297 | | |
297 | 298 | | |
298 | 299 | | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
299 | 501 | | |
300 | 502 | | |
301 | 503 | | |
| |||
0 commit comments