From sky at viridian-project.de Wed Aug 5 08:08:53 2009 From: sky at viridian-project.de (Leslie P. Polzer) Date: Wed, 5 Aug 2009 10:08:53 +0200 (CEST) Subject: [cl-json-devel] Contrib: simplified camel case Message-ID: <12b906d569bfe6d08490dd3cd8e923f1.squirrel@mail.stardawn.org> You might want to include this in camel-case.lisp or contrib. It's barely tested so far though. (defun simplified-camel-case-to-lisp (camel-string) "We don't want + and * all over the place." (declare (string camel-string)) (let ((*print-pretty* nil)) (with-output-to-string (result) (loop for c across camel-string with last-was-lowercase when (and last-was-lowercase (upper-case-p c)) do (princ "-" result) if (lower-case-p c) do (setf last-was-lowercase t) else do (setf last-was-lowercase nil) do (princ (char-upcase c) result))))) Leslie -- http://www.linkedin.com/in/polzer From henrik at evahjelte.com Mon Aug 10 13:51:05 2009 From: henrik at evahjelte.com (Henrik Hjelte) Date: Mon, 10 Aug 2009 15:51:05 +0200 Subject: [cl-json-devel] Not interning object keys In-Reply-To: References: <68315BE4-8174-47F3-AC85-AEF92609DB7E@gmail.com> <50e8e4f60906261439j683c3491m1d59e42922415eca@mail.gmail.com> <6BFE3EB4-9AF1-4324-B77E-861828D5B3DA@gmail.com> Message-ID: <50e8e4f60908100651l5015b7bcl93ef9356434955ee@mail.gmail.com> On Tue, Jun 30, 2009 at 5:41 PM, Red Daly wrote: > On Fri, Jun 26, 2009 at 3:20 PM, Boris Smilga > wrote: >> >> Just a minor cavil: does not *STRING-TO-KEY* (or maybe >> *IDENTIFIER-NAME-TO-KEY*) seem like a better name for this variable? > > I would prefer *IDENTIFIER-NAME-TO-KEY* since it gives more context about > what the function is used for.? *STRING-TO-KEY* is confusing since it's > unclear where the "string" is coming from. I have now applied this (with one slight difference) and added a testcase. Also I have made a function safe-json-intern that I think should be safe from attacks. I pasted the testcases below. Thanks! -Henrik (test custom-identifier-name-to-key "Interns of many unique symbols could potentially use a lot of memory. An attack could exploit this by submitting something that is passed through cl-json that has many very large, unique symbols. See the safe-symbols-parsing function here for a cure." (with-decoder-simple-list-semantics (flet ((safe-symbols-parsing (name) (or (find-symbol name *json-symbols-package*) (error "unknown symbols not allowed")))) (let ((good-symbols "{\"car\":1,\"cdr\":2}") (bad-symbols "{\"could-be\":1,\"a-denial-of-service-attack\":2}") (*json-symbols-package* (find-package :cl)) (*identifier-name-to-key* #'safe-symbols-parsing)) (is (equal '((car . 1) (cdr . 2)) (decode-json-from-string good-symbols))) (signals error (decode-json-from-string bad-symbols)))))) (test safe-json-intern (with-decoder-simple-list-semantics (let ((good-symbols "{\"car\":1,\"cdr\":2}") (bad-symbols "{\"could-be\":1,\"a-denial-of-service-attack\":2}") (*json-symbols-package* (find-package :cl)) (*identifier-name-to-key* #'safe-json-intern)) (is (equal '((car . 1) (cdr . 2)) (decode-json-from-string good-symbols))) (signals unknown-symbol-error (decode-json-from-string bad-symbols))))) From henrik at evahjelte.com Mon Aug 10 20:07:56 2009 From: henrik at evahjelte.com (Henrik Hjelte) Date: Mon, 10 Aug 2009 22:07:56 +0200 Subject: [cl-json-devel] Contrib: simplified camel case In-Reply-To: <12b906d569bfe6d08490dd3cd8e923f1.squirrel@mail.stardawn.org> References: <12b906d569bfe6d08490dd3cd8e923f1.squirrel@mail.stardawn.org> Message-ID: <50e8e4f60908101307w40bd1472o27f5993879c7c1e6@mail.gmail.com> On Wed, Aug 5, 2009 at 10:08 AM, Leslie P. Polzer wrote: > > You might want to include this in camel-case.lisp or > contrib. It's barely tested so far though. I have added the simplified-camel-case-to-lisp function and made a testcase that shows how it differs to the ordinary camel-case-to-lisp (below) For the speed hungry, it seems a bit faster than the ordinary camel-case-to-lisp (performance test also in a new testcase). Thanks a lot, Henrik (test json-object-camel-case (with-decoder-simple-list-semantics (let ((*json-symbols-package* (find-package :keyword))) (is (equalp '((:hello-key . "hej") (:*hi-starts-with-upper-case . "tjena") (:+json+-all-capitals . "totae majusculae") (:+two-words+ . "duo verba") (:camel-case--*mixed--+4-parts+ . "partes miscella quatuor")) (decode-json-from-string " { \"helloKey\" : \"hej\" , \"HiStartsWithUpperCase\" : \"tjena\", \"JSONAllCapitals\": \"totae majusculae\", \"TWO_WORDS\": \"duo verba\", \"camelCase_Mixed_4_PARTS\": \"partes miscella quatuor\" }")))))) (test json-object-simplified-camel-case ;; Compare this with json-object-camel-case above (with-decoder-simple-list-semantics (let ((*json-symbols-package* (find-package :keyword)) (*json-identifier-name-to-lisp* #'simplified-camel-case-to-lisp)) (is (equalp '((:hello-key . "hej") (:hi-starts-with-upper-case . "tjena") (:jsonall-capitals . "totae majusculae") (:two_words . "duo verba") (:camel-case_mixed_4_parts . "partes miscella quatuor")) (decode-json-from-string " { \"helloKey\" : \"hej\" , \"HiStartsWithUpperCase\" : \"tjena\", \"JSONAllCapitals\": \"totae majusculae\", \"TWO_WORDS\": \"duo verba\", \"camelCase_Mixed_4_PARTS\": \"partes miscella quatuor\" }"))))))