--- JSON-XS/XS.xs 2007/03/23 16:13:59 1.8 +++ JSON-XS/XS.xs 2007/03/23 17:40:29 1.9 @@ -135,7 +135,7 @@ { uch = utf8n_to_uvuni (str, end - str, &clen, UTF8_CHECK_ONLY); if (clen == (STRLEN)-1) - croak ("malformed UTF-8 character in string, cannot convert to JSON"); + croak ("malformed or illegal unicode character in string [%.11s], cannot convert to JSON", str); } else { @@ -143,6 +143,9 @@ clen = 1; } + if (uch > 0x10FFFFUL) + croak ("out of range codepoint (0x%lx) encountered, unrepresentable in JSON", (unsigned long)uch); + if (uch < 0x80 || enc->flags & F_ASCII) { if (uch > 0xFFFFUL) @@ -398,31 +401,33 @@ } else if (SvROK (sv)) { + SV *rv = SvRV (sv); + if (!--enc->max_recurse) croak ("data structure too deep (hit recursion limit)"); - sv = SvRV (sv); - - switch (SvTYPE (sv)) + switch (SvTYPE (rv)) { - case SVt_PVAV: encode_av (enc, (AV *)sv); break; - case SVt_PVHV: encode_hv (enc, (HV *)sv); break; + case SVt_PVAV: encode_av (enc, (AV *)rv); break; + case SVt_PVHV: encode_hv (enc, (HV *)rv); break; default: - croak ("JSON can only represent references to arrays or hashes"); + croak ("encountered %s, but JSON can only represent references to arrays or hashes", + SvPV_nolen (sv)); } } else if (!SvOK (sv)) encode_str (enc, "null", 4, 0); else - croak ("encountered perl type that JSON cannot handle"); + croak ("encountered perl type (%s,0x%x) that JSON cannot handle, you might want to report this", + SvPV_nolen (sv), SvFLAGS (sv)); } 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)"); + croak ("hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this)"); enc_t enc; enc.flags = flags; @@ -903,7 +908,7 @@ 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)"); + croak ("JSON text must be an object or array (but found number, string, true, false or null, use allow_nonref to allow this)"); return sv; }