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 incorrect array encoding in config produced by RollbarJsHelper #459

Merged
merged 1 commit into from
Jan 17, 2023

Conversation

vilius-g
Copy link
Contributor

When building JS code with RollbarJsHelper and passing configuration
parameters that are arrays, those arrays in the final JS output are
incorrectly encoded as objects.

@bishopb bishopb self-assigned this Dec 3, 2020
@bishopb bishopb added Rank: 2 - Major Tackle when there are no actionable Critical requests. Status: 3 - Construction The request is being worked on. Type: Bug Fix a component so that its behavior aligns with its documentation. labels Dec 3, 2020
@bishopb
Copy link
Contributor

bishopb commented Dec 3, 2020

Thanks for taking the time to submit this! I agree; the current code seems buggy.

Digging a little, looks like JSON_FORCE_OBJECT was introduced back in 2017 by @rokob. I think the intent of that change was to ensure the configuration object at the highest level was always an object, but it seems to have neglected the side effect of forcing deep PHP arrays to JSON objects (eg, a configuration of [ "a" => [ ] ] produces {"a":{}} instead of the desired {"a":[]}.

We'll get this in the pipeline for change soon.

src/RollbarJsHelper.php Outdated Show resolved Hide resolved
@rokob
Copy link
Contributor

rokob commented Dec 4, 2020

Yeah I was trying to only force the top-level to be an object. PHP never ceases to amaze me. I see now in the docs that there is a user comment about this behavior. Although the main docs don't mention anything about this being applied to the entire structure:

JSON_FORCE_OBJECT (int)
Outputs an object rather than an array when a non-associative array is used. Especially useful when the recipient of the output is expecting an object and the array is empty. Available as of PHP 5.3.0.

@bishopb bishopb removed their assignment Feb 13, 2022
@danielmorell danielmorell self-assigned this Dec 20, 2022
@danielmorell danielmorell requested review from danielmorell and removed request for waltjones January 16, 2023 15:34
Copy link
Collaborator

@danielmorell danielmorell left a comment

Choose a reason for hiding this comment

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

@vilius-g sorry about the long delay! This looks great! I think we just need to fix the merge conflicts before getting this in. Can you do that?

When building JS code with RollbarJsHelper and passing configuration parameters that are arrays, those arrays in the final JS output are incorrectly encoded as objects.
@vilius-g
Copy link
Contributor Author

I have fixed merge conflicts.

There seems some issue with CI, but it is possibly one-off as I am unable to reproduce it.

Copy link
Collaborator

@danielmorell danielmorell left a comment

Choose a reason for hiding this comment

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

Thank you @vilius-g. I ran the failed tests again and they passed. We sometimes get false negatives when performing the network part of the test suite.

This looks great! Thank you for the work on this!

@danielmorell danielmorell merged commit 4897fa2 into rollbar:master Jan 17, 2023
@vilius-g vilius-g deleted the js-config-encode branch January 18, 2023 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rank: 2 - Major Tackle when there are no actionable Critical requests. Status: 3 - Construction The request is being worked on. Type: Bug Fix a component so that its behavior aligns with its documentation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants