From 0bf9cce4b734d107d71f5364bef6d042d83a4ed2 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Thu, 30 Aug 2012 00:36:44 +0200 Subject: [PATCH] Fix ein:worksheet-to-json When there is no metadata, do not include it in JSON data to avoid converting nil to JSON (which yields null). --- lisp/ein-worksheet.el | 2 +- tests/test-ein-worksheet.el | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lisp/ein-worksheet.el b/lisp/ein-worksheet.el index 8cd81c0..a453d10 100644 --- a/lisp/ein-worksheet.el +++ b/lisp/ein-worksheet.el @@ -228,7 +228,7 @@ current buffer." c (ein:funcall-packed discard-output-p c))) (ein:worksheet-get-cells ws))))) `((cells . ,(apply #'vector cells)) - (metadata . ,(oref ws :metadata))))) + ,@(ein:aand (oref ws :metadata) `((metadata . ,it)))))) (defmethod ein:worksheet-save-cells ((ws ein:worksheet)) "Save cells in worksheet buffer in cache before killing the buffer. diff --git a/tests/test-ein-worksheet.el b/tests/test-ein-worksheet.el index f6d2881..636f00f 100644 --- a/tests/test-ein-worksheet.el +++ b/tests/test-ein-worksheet.el @@ -23,6 +23,9 @@ (ein:worksheet-from-json ws-1 (ein:json-read-from-string (json-encode json-0)))))) + (let* ((found (assoc 'metadata json-0))) + (when found + (should (cdr found)))) (should (equal json-0 json-1)))) (ert-deftest ein:worksheet-to-json/empty ()