m-lua-scripting: always parse JSON to String if its type is not recognized
This allows parsing JSON strings without quotes.
This commit is contained in:
@@ -123,13 +123,6 @@ push_luajson (lua_State *L, WpSpaJson *json)
|
|||||||
lua_pushnumber (L, value);
|
lua_pushnumber (L, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* String */
|
|
||||||
else if (wp_spa_json_is_string (json)) {
|
|
||||||
g_autofree gchar *value = wp_spa_json_parse_string (json);
|
|
||||||
g_warn_if_fail (value);
|
|
||||||
lua_pushstring (L, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Array */
|
/* Array */
|
||||||
else if (wp_spa_json_is_array (json)) {
|
else if (wp_spa_json_is_array (json)) {
|
||||||
g_auto (GValue) item = G_VALUE_INIT;
|
g_auto (GValue) item = G_VALUE_INIT;
|
||||||
@@ -163,6 +156,13 @@ push_luajson (lua_State *L, WpSpaJson *json)
|
|||||||
lua_setfield (L, -2, key_str);
|
lua_setfield (L, -2, key_str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Otherwise alwyas parse as String to allow parsing strings without quotes */
|
||||||
|
else {
|
||||||
|
g_autofree gchar *value = wp_spa_json_parse_string (json);
|
||||||
|
g_warn_if_fail (value);
|
||||||
|
lua_pushstring (L, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@@ -169,6 +169,14 @@ val = json:parse ()
|
|||||||
assert (val[1] == "foo")
|
assert (val[1] == "foo")
|
||||||
assert (val[2] == "bar")
|
assert (val[2] == "bar")
|
||||||
|
|
||||||
|
json = Json.Raw ("[foo, bar]")
|
||||||
|
assert (json:is_array())
|
||||||
|
assert (json:get_data() == "[foo, bar]")
|
||||||
|
assert (json:get_data() == json:to_string())
|
||||||
|
val = json:parse ()
|
||||||
|
assert (val[1] == "foo")
|
||||||
|
assert (val[2] == "bar")
|
||||||
|
|
||||||
json = Json.Raw ("{\"name\": \"wireplumber\", \"version\": [0, 4, 7]}")
|
json = Json.Raw ("{\"name\": \"wireplumber\", \"version\": [0, 4, 7]}")
|
||||||
assert (json:is_object())
|
assert (json:is_object())
|
||||||
assert (json:get_data() == "{\"name\": \"wireplumber\", \"version\": [0, 4, 7]}")
|
assert (json:get_data() == "{\"name\": \"wireplumber\", \"version\": [0, 4, 7]}")
|
||||||
|
Reference in New Issue
Block a user