Skip to content

Commit

Permalink
Fixed incorrect null handling with json apis
Browse files Browse the repository at this point in the history
Fixed toJson and parseJson incorrectly handling null values in arrays
  • Loading branch information
omoflop authored and UnlikePaladin committed Sep 17, 2023
1 parent 253971b commit 7564d15
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ public static LuaValue asLuaValue(JsonElement value) {
} else if (value.isJsonArray()) {
JsonArray arr = value.getAsJsonArray();
LuaTable table = new LuaTable();
int i = 1;
for (JsonElement element : arr) {
table.insert(table.length()+1, asLuaValue(element));
table.insert(i, asLuaValue(element));
i++;
}
return table;
} else if (value.isJsonNull()) {
Expand Down
6 changes: 4 additions & 2 deletions common/src/main/java/org/figuramc/figura/utils/LuaUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,10 @@ public static JsonElement asJsonValue(LuaValue value) {
// If it's an "array" (uses numbers as keys)
if (checkTableArray(table)) {
JsonArray arr = new JsonArray();
for (int i = 0; i < table.length(); i++) {
arr.add(asJsonValue(table.get(i+1)));
LuaValue[] keys = table.keys();
int arrayLength = keys[keys.length-1].checkint();
for(int i = 1; i <= arrayLength; i++) {
arr.add(asJsonValue(table.get(i)));
}
return arr;
}
Expand Down

0 comments on commit 7564d15

Please sign in to comment.