From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Yoichi Nakayama Newsgroups: gmane.emacs.bugs Subject: bug#24252: 25.1; json.el doesn't distinguish null and empty object Date: Sun, 21 Aug 2016 21:11:16 +0900 Message-ID: References: <0e859022-309d-576d-62ea-acaddb10a0c2@yandex.ru> <4d97b2a8-5b96-6c22-7b00-95ef8bd5f6fd@yandex.ru> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: blaine.gmane.org 1471781541 8323 195.159.176.226 (21 Aug 2016 12:12:21 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 21 Aug 2016 12:12:21 +0000 (UTC) Cc: 24252@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Aug 21 14:12:17 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bbRbs-0001mc-0H for geb-bug-gnu-emacs@m.gmane.org; Sun, 21 Aug 2016 14:12:16 +0200 Original-Received: from localhost ([::1]:36453 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bbRbp-0007me-0X for geb-bug-gnu-emacs@m.gmane.org; Sun, 21 Aug 2016 08:12:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59183) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bbRbi-0007mJ-RL for bug-gnu-emacs@gnu.org; Sun, 21 Aug 2016 08:12:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bbRbe-0008DW-KO for bug-gnu-emacs@gnu.org; Sun, 21 Aug 2016 08:12:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:37839) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bbRbe-0008DS-Gu for bug-gnu-emacs@gnu.org; Sun, 21 Aug 2016 08:12:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bbRbe-0003FY-5a for bug-gnu-emacs@gnu.org; Sun, 21 Aug 2016 08:12:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Yoichi Nakayama Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 21 Aug 2016 12:12:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 24252 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 24252-submit@debbugs.gnu.org id=B24252.147178148412443 (code B ref 24252); Sun, 21 Aug 2016 12:12:02 +0000 Original-Received: (at 24252) by debbugs.gnu.org; 21 Aug 2016 12:11:24 +0000 Original-Received: from localhost ([127.0.0.1]:35551 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bbRb2-0003Ed-6k for submit@debbugs.gnu.org; Sun, 21 Aug 2016 08:11:24 -0400 Original-Received: from mail-it0-f42.google.com ([209.85.214.42]:35384) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bbRb0-0003EO-Mh for 24252@debbugs.gnu.org; Sun, 21 Aug 2016 08:11:22 -0400 Original-Received: by mail-it0-f42.google.com with SMTP id x131so66460385ite.0 for <24252@debbugs.gnu.org>; Sun, 21 Aug 2016 05:11:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=yPW95dhXCZEu8LBahXrnkIhHI7+YzZvZsZFJoP7p2tg=; b=ZqaEYfP7HCZ6iEZqPQDnQ1w6FABqmo5IU6uNQcdahxyXlXvNqiC6Km+7g3dn6Eb+VL UgLbe/9cFqkVKqiaW5J0e4rgnABzhB/E2JErFt2BQCCm0CCCD+yjm+iyeGrJSlmkUHit Y5FXRZ7Ig2N13ia0uD03hk/1TgGeTO2g8hqm2lcOOiY95PV+DKnkNPO+gHXAwMBNtqYs NrvEUqhSf/CzItR4CPin2QcfaC0/XlYjV2v5Fwdo4TTnqFz7PP5UgeaBNELIFjiep3Jc oJbcHEB3DU918FhjuGljNl0SmCEcKkH1cVX3TjoEH3lSJMvMXHB+JM7liNfw2xPHXQOL 7X/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=yPW95dhXCZEu8LBahXrnkIhHI7+YzZvZsZFJoP7p2tg=; b=NENcxJTRqD3L9LRtt94DX8SXYEmuacToeW6fMy4nUnL2VuXAqxab+zjWrosmCYp93J 3RILkPL5Lgw6ieRH4oNbbA9jzf57gy85zuE+y+PEbz60VB84T1MjG/4QHCZsQtdE/VAM 2kceRJcJz7AZyRpqZJxOVZj4JK+6VMhg+cSjvkaAc6soMl+MY+xte3nQ3JHfvQTAtzma Usysp6hoH59YlsRo7SqKGbeIpauqlL4QtcFoF3lWi5QIkeWWkhTLhw1YUKmhnI1coTAC wd+w1EeLfFy0CjiXugL3KFD4Ww/zifvFlWM4GcS0YEz00+4r5qjQPYoHufMuCb79YUE1 CFtw== X-Gm-Message-State: AEkoouv38p8fRohAWfKMFh5hoFLLJxZM2oSDu7GTMdEClenOZhMKPyqE704Pyk6XhEAjvQ0gUzDT2IRQcdFf9Q== X-Received: by 10.36.254.72 with SMTP id w69mr15010428ith.52.1471781477189; Sun, 21 Aug 2016 05:11:17 -0700 (PDT) Original-Received: by 10.107.3.18 with HTTP; Sun, 21 Aug 2016 05:11:16 -0700 (PDT) In-Reply-To: <4d97b2a8-5b96-6c22-7b00-95ef8bd5f6fd@yandex.ru> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:122449 Archived-At: There was another potential bug that json-encode-key wrongly interpret symbols internally used in json.el. The problem is not caused by my previous patch, but the patch introduces another internal symbol :json-null and increase possibility to encounter it. Following patch will fix it and make it safe to apply my second patch >From 4d3ad1d3bbe6b3e47743f42427ac26cf316c12b5 Mon Sep 17 00:00:00 2001 From: Yoichi Nakayama Date: Sun, 21 Aug 2016 20:24:03 +0900 Subject: [PATCH] Make json-encode-key not to signal with valid keys Despite strings like ":json-false", "t", "nil" are valid object key, their elisp representation were confused with internal symbols in json-encode-key and cause json-key-format error unexpectedly. * (json-encode-key): Rewrite without using json-encode. --- lisp/json.el | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/lisp/json.el b/lisp/json.el index a439f77..a387b08 100644 --- a/lisp/json.el +++ b/lisp/json.el @@ -425,14 +425,30 @@ representation will be parsed correctly." (push "\"" res) (apply #'concat "\"" (nreverse res)))) -(defun json-encode-key (object) - "Return a JSON representation of OBJECT. -If the resulting JSON object isn't a valid JSON object key, -this signals `json-key-format'." - (let ((encoded (json-encode object))) - (unless (stringp (json-read-from-string encoded)) - (signal 'json-key-format (list object))) - encoded)) +(defun json-encode-key (key) + "Return a JSON representation of object key. +If key isn't valid Elisp object as key, this signals `json-key-format'." + (let ((json-key-type + (if (eq json-key-type nil) + (cdr (assq json-object-type '((hash-table . string) + (alist . symbol) + (plist . keyword)))) + json-key-type))) + (json-encode-string + (cond ((eq json-key-type 'string) + (if (stringp key) + key + (signal 'json-key-format (list key)))) + ((eq json-key-type 'symbol) + (if (symbolp key) + (symbol-name key) + (signal 'json-key-format (list key)))) + ((eq json-key-type 'keyword) + (if (keywordp key) + (substring (symbol-name key) 1) + (signal 'json-key-format (list key)))) + (t + (signal 'json-error (list key))))))) ;;; JSON Objects -- 2.8.1