fix: Makes encoding always transform empty tables into arrays #174
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds the flag
encode_empty_table_as_object
with the valuefalse
, in order to ensure that empty Lua tables will always be transformed into empty JSON arrays when usingcjson.encode
.How Has This Been Tested?
I made a request where the previous version of the plugin was enabled and confirmed that the problem was occurring:
![image](https://private-user-images.githubusercontent.com/9416565/289889180-c7d9f25b-2526-44c1-8b02-7ffdbb1792c4.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEzMDM4MDEsIm5iZiI6MTcyMTMwMzUwMSwicGF0aCI6Ii85NDE2NTY1LzI4OTg4OTE4MC1jN2Q5ZjI1Yi0yNTI2LTQ0YzEtOGIwMi03ZmZkYmIxNzkyYzQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcxOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MThUMTE1MTQxWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MmFkNTMxMmQzNjU4YWM0NjliMDUzY2I4YjllZTY1YmE3NTQ3MzU0YmI2NWZlZTk2ODVjNjlhOTU2MTQwYjljZiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.bY37yd8jmZJZDAQoAOgolpmbQ-e2k7inb3dthN6-aMk)
Then I applied this version of the plugin and made the same request again. This time, empty arrays were correctly preserved:
![image](https://private-user-images.githubusercontent.com/9416565/289889658-c2f25d7a-8e9b-4776-a39e-a4696f41c4b6.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEzMDM4MDEsIm5iZiI6MTcyMTMwMzUwMSwicGF0aCI6Ii85NDE2NTY1LzI4OTg4OTY1OC1jMmYyNWQ3YS04ZTliLTQ3NzYtYTM5ZS1hNDY5NmY0MWM0YjYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcxOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MThUMTE1MTQxWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MGMxOTczNzUwN2FiMmE1NzdlNWQ0ZGVlNDQxMGMxOWE0OTVhMmY4ZjUzNDNhMjFjMjRkMzFhYTgxODE4MDIyZiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.55INScLJ-jYWfhCMK2dbRmCrdmWsyyXRkXdK3ckexkQ)