Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

#311 - Update NormalizeUploadedFiles to handle multi-dimension recursively #312

Conversation

precariouspanther
Copy link
Contributor

@precariouspanther precariouspanther commented Jul 9, 2018

To address #311 (Some/All?) SAPI's index the tmp_name etc common fields from the point that a numerically indexed array is encountered which is causing Diactoros to fail fatally with form uploads that use multi-dimensional named fields containing a numeric index (as well as not converting all leaf nodes for deeper hierarchies of file upload field names).

This change updates normalizeUploadedFiles to be recursive and introduces several tests to verify the behaviour matches the PSR-7 spec + the scenario not mentioned by the spec.

Note: given the number of "private" functions being encapsulated in this larger function it may be worth considering converting this to an object instead especially as the recursion and lack of hoisting makes declaration order of the "private" functions non-idiomatic for most PHP engineers. I avoided significant changes here given it's just a fix, but food for thought!

Also, first time I've contributed to this project: please let me know if I've incorrectly interpreted the contrib. standards and I need to fix anything 😃

@PascalZajac @serroba FYI

@@ -24,6 +24,45 @@
*/
function normalizeUploadedFiles(array $files)
{
/**
* @param array $tmpNameTree
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please document the types of these arrays?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do 👍
EDIT Mis-remembered, have pushed commit to address the new function.

$tmpNameTree[$key],
$sizeTree[$key],
$errorTree[$key],
$nameTree[$key] ?? null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're currently still supporting PHP 5.6, so this needs to become:

isset($nameTree[$key]) ? $nameTree[$key] : null

(Here and everywhere else you use null coalesce.)

Adam Benson and others added 2 commits July 9, 2018 15:57
Since we support PHP 5.6 still in this library, we cannot yet use null
coalesce.
@weierophinney weierophinney force-pushed the 311-recursive-normalize-files branch from 790f624 to 1172baf Compare July 9, 2018 21:02
@weierophinney weierophinney merged commit 2bbccb7 into zendframework:master Jul 9, 2018
weierophinney added a commit that referenced this pull request Jul 9, 2018
weierophinney added a commit that referenced this pull request Jul 9, 2018
@precariouspanther precariouspanther deleted the 311-recursive-normalize-files branch July 9, 2018 23:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants