--- JSON-XS/XS.xs 2007/03/22 17:28:50 1.2 +++ JSON-XS/XS.xs 2007/03/22 18:10:29 1.3 @@ -13,6 +13,7 @@ #define F_SPACE_BEFORE 0x00000010 #define F_SPACE_AFTER 0x00000020 #define F_JSON_RPC 0x00000040 +#define F_ALLOW_NONREF 0x00000080 #define F_PRETTY F_INDENT | F_SPACE_BEFORE | F_SPACE_AFTER #define F_DEFAULT 0 @@ -361,6 +362,9 @@ static SV * encode_json (SV *scalar, UV flags) { + if (!(flags & F_ALLOW_NONREF) && !SvROK (scalar)) + croak ("hash- or arraref required (not a simple scalar, use allow_nonref to allow this)"); + enc_t enc; enc.flags = flags; enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); @@ -774,8 +778,12 @@ dec.cur != dec.end ? SvPV_nolen (uni) : "(end of string)"); } - sv_dump (sv);//D - return sv_2mortal (sv); + sv = sv_2mortal (sv); + + if (!(dec.flags & F_ALLOW_NONREF) && !SvROK (sv)) + croak ("JSON object or array expected (but number, string, true, false or null found, use allow_nonref to allow this)"); + + return sv; } MODULE = JSON::XS PACKAGE = JSON::XS @@ -813,6 +821,7 @@ space_after = F_SPACE_AFTER json_rpc = F_JSON_RPC pretty = F_PRETTY + allow_nonref = F_ALLOW_NONREF CODE: { UV *uv = SvJSON (self);