shithub: libmujs

Download patch

ref: ddd1e5ebe619baf5794d3e2e4a66a732df4ddeb3
parent: e690d31ee365bebde97acf24035fc028622fbe2d
author: isRyven <[email protected]>
date: Sat Dec 21 09:29:00 EST 2019

Issue 126: accept String and Number objects as space parameter

--- a/json.c
+++ b/json.c
@@ -329,7 +329,7 @@
 
 	gap = NULL;
 
-	if (js_isnumber(J, 3)) {
+	if (js_isnumber(J, 3) || (js_isobject(J, 3) && js_toobject(J, 3)->type == JS_CNUMBER)) {
 		n = js_tointeger(J, 3);
 		if (n < 0) n = 0;
 		if (n > 10) n = 10;
@@ -336,7 +336,7 @@
 		memset(buf, ' ', n);
 		buf[n] = 0;
 		if (n > 0) gap = buf;
-	} else if (js_isstring(J, 3)) {
+	} else if (js_isstring(J, 3) || (js_isobject(J, 3) && js_toobject(J, 3)->type == JS_CSTRING)) {
 		s = js_tostring(J, 3);
 		n = strlen(s);
 		if (n > 10) n = 10;