From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/83336 Path: news.gmane.org!not-for-mail From: Philipp Gesang Newsgroups: gmane.comp.tex.context Subject: [util-jsn] incorrect handling of escapes Date: Mon, 8 Jul 2013 00:56:29 +0200 Message-ID: <20130707225628.GA7955@phlegethon> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1048322398==" X-Trace: ger.gmane.org 1373238705 22622 80.91.229.3 (7 Jul 2013 23:11:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 7 Jul 2013 23:11:45 +0000 (UTC) To: ConTeXt ML Original-X-From: ntg-context-bounces@ntg.nl Mon Jul 08 01:11:47 2013 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([195.12.62.10]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Uvxt2-0008Fx-IC for gctc-ntg-context-518@m.gmane.org; Mon, 08 Jul 2013 00:56:56 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 74073101EE; Mon, 8 Jul 2013 00:56:55 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id RXi1uCC52oiE; Mon, 8 Jul 2013 00:56:53 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [IPv6:::1]) by balder.ntg.nl (Postfix) with ESMTP id 3986E101E9; Mon, 8 Jul 2013 00:56:53 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id E0D0B101E9 for ; Mon, 8 Jul 2013 00:56:50 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Hm7IBAAdZyer for ; Mon, 8 Jul 2013 00:56:49 +0200 (CEST) Original-Received: from filter1-til.mf.surf.net (filter1-til.mf.surf.net [194.171.167.217]) by balder.ntg.nl (Postfix) with ESMTP id 1EC49101E0 for ; Mon, 8 Jul 2013 00:56:39 +0200 (CEST) Original-Received: from relay2.uni-heidelberg.de (relay2.uni-heidelberg.de [129.206.210.211]) by filter1-til.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with ESMTP id r67MubxR012762 for ; Mon, 8 Jul 2013 00:56:38 +0200 Original-Received: from ix.urz.uni-heidelberg.de (cyrus-portal.urz.uni-heidelberg.de [129.206.100.176]) by relay2.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id r67MuboD003454 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 8 Jul 2013 00:56:37 +0200 Original-Received: from extmail.urz.uni-heidelberg.de (extmail.urz.uni-heidelberg.de [129.206.100.140]) by ix.urz.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id r67MuacT015878 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 8 Jul 2013 00:56:36 +0200 Original-Received: from localhost (p50845AC5.dip0.t-ipconnect.de [80.132.90.197]) (authenticated bits=0) by extmail.urz.uni-heidelberg.de (8.13.4/8.13.1) with ESMTP id r67MuZ2W028281 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Mon, 8 Jul 2013 00:56:36 +0200 Mail-Followup-To: ConTeXt ML X-Operating-System: Linux phlegethon 3.9.5-1-ARCH X-NSA: "None of you business!" User-Agent: Mutt/1.5.21 (2010-09-15) X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=129.206.210.211; country=DE; region=01; city=Heidelberg; latitude=49.4167; longitude=8.7000; http://maps.google.com/maps?q=49.4167,8.7000&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 0RJVyUBvh - c5bcf92c9b39 - 20130708 (trained as not-spam) X-Scanned-By: CanIt (www . roaringpenguin . com) on 194.171.167.217 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.14 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: ntg-context-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:83336 Archived-At: --===============1048322398== Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="pZs/OQEoSSbxGlYw" Content-Disposition: inline --pZs/OQEoSSbxGlYw Content-Type: multipart/mixed; boundary="JWEK1jqKZ6MHAcjA" Content-Disposition: inline --JWEK1jqKZ6MHAcjA Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, the JSON parser handles backslash escapes improperly. Example: local data = [[ { "escapes" : "(\")(\\)(\b)(\f)(\n)(\r)(\t)", "invalid" : "\'\v" } ]] local stuff = utilities.json.tolua (data) inspect(stuff) Currently it chokes on double quotes and treats the other escapes like Lua. Fix suggestion attached. Best regards, Philipp --JWEK1jqKZ6MHAcjA Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="util-jsn.patch" Content-Transfer-Encoding: quoted-printable --- util-jsn.lua.orig 2013-07-08 00:09:21.834400224 +0200 +++ util-jsn.lua 2013-07-08 00:54:25.889668771 +0200 @@ -15,7 +15,7 @@ -- Reminder for me: check usage in framework and extend when needed. Also = document -- it in the cld lib documentation. =20 -local P, V, R, S, C, Cc, Cs, Ct, Cf, Cg =3D lpeg.P, lpeg.V, lpeg.R, lpeg.S= , lpeg.C, lpeg.Cc, lpeg.Cs, lpeg.Ct, lpeg.Cf, lpeg.Cg +local P, V, R, S, C, Cc, Cs, Ct, Cf, Cg, Cp =3D lpeg.P, lpeg.V, lpeg.R, lp= eg.S, lpeg.C, lpeg.Cc, lpeg.Cs, lpeg.Ct, lpeg.Cf, lpeg.Cg, lpeg.Cp local lpegmatch =3D lpeg.match local format =3D string.format local utfchar =3D utf.char @@ -42,7 +42,15 @@ local whitespace =3D lpeg.patterns.whitespace local optionalws =3D whitespace^0 =20 -local escape =3D C(P("\\u") / "0x" * S("09","AF","af")) / function(s) = return utfchar(tonumber(s)) end +local escape_a =3D C(P("\\u") / "0x" * S("09","AF","af")) / function(s) = return utfchar(tonumber(s)) end +local escape_b =3D P([[\]]) / "" * S([["\/]]) --> represent themselves +local escape_c =3D P([[\b]]) / "\010" --> backspace + + P([[\f]]) / "\014" --> form feed + + P([[\n]]) / "\n" + + P([[\r]]) / "\r" + + P([[\t]]) / "\t" +local invalid =3D P([[\]]) / "" * (Cp() * P(1) / function (pos, chr) --= [[ bug_user_about_invalid_escape (chr, pos) ]] return "" end) +local escape =3D escape_a + escape_b + escape_c + invalid local jstring =3D dquote * Cs((escape + (1-dquote))^0) * dquote local jtrue =3D P("true") * Cc(true) local jfalse =3D P("false") * Cc(false) --JWEK1jqKZ6MHAcjA-- --pZs/OQEoSSbxGlYw Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.20 (GNU/Linux) iQEcBAEBCgAGBQJR2fIdAAoJEI7yfcKNwM1+KOQIALRmBbedSJK/ns+9ugp8ubgH 2zAZl62qV7PCiKEDlaYFJ85jUwSDWfLVwk374tN0xj0C0BLZfOD6NNfI5m6UI8Ez A5pFwYIY9ymUH7Vlz3Yh7ByCr7nvXuu/eITIMxR1xIzK0D6v6NdsXevDvENj//QS yLSHZUBwjvhTJ5LjVtaOiB7vS1O9zQm1q9pquEhEYtlPUh1P/d6OiUXrMvATyTX6 azPJeIYIuv1W8jJpwpD9ffHMVAn/YtR9aOYSqPqUVLUzAPUW6XF8XJhyhGCPFVwG G5PNVRi4LoXspW/UBiZWza44oUc4rgchVkMegMZYp9KJ0vAsosgq9FcsGmipJ3A= =7YJ1 -----END PGP SIGNATURE----- --pZs/OQEoSSbxGlYw-- --===============1048322398== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________ --===============1048322398==--