Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing multidimensional array from multipart #186

Merged
merged 1 commit into from
Jan 7, 2025

Conversation

Vinimaks
Copy link
Contributor

@Vinimaks Vinimaks commented Jan 7, 2025

During parsing a multipart array there is a check if the current segment is empty to set a value. Basically, adding a new element to an array.

It works perfectly fine for simple arrays like:

  • 'categories[]: 1'
  • 'categories[]: 2'

But sometimes the array key is also specified, fx:

  • 'categories[0]: 1'
  • 'categories[1]: 2'

Or something more complicated as Laravel Nova does:

  • 'options[0][fields][id]: 1'
  • 'options[0][fields][participants]: 1'

In that case the check:

if (empty($segment = substr($segment, 0, -1))) {
    $pointer = &$pointer[];
} else {
    $pointer = &$pointer[$segment];
}

Will fail as empty considers the first array key ('0') as true
image
Thus each time a new array element created instead of adding to the existing one, which causes some unexpected result

Report to that issue in the Nova issues repository: laravel/nova-issues#6229

@taylorotwell taylorotwell merged commit 9dde475 into laravel:2.0 Jan 7, 2025
7 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.

2 participants