From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Chong Yidong Newsgroups: gmane.emacs.bugs Subject: bug#679: 23.0.60; Function json-read-number does not handle complete Javascript spec Date: Tue, 12 Aug 2008 23:42:26 -0400 Message-ID: <87r68th97h.fsf@stupidchicken.com> Reply-To: Chong Yidong , 679@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1218600461 1892 80.91.229.12 (13 Aug 2008 04:07:41 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 13 Aug 2008 04:07:41 +0000 (UTC) Cc: 679@emacsbugs.donarmstrong.com To: "Edward O'Connor" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Aug 13 06:08:32 2008 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KT7ew-0005xx-BV for geb-bug-gnu-emacs@m.gmane.org; Wed, 13 Aug 2008 06:08:30 +0200 Original-Received: from localhost ([127.0.0.1]:57172 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KT7dz-0008Mh-Rt for geb-bug-gnu-emacs@m.gmane.org; Wed, 13 Aug 2008 00:07:31 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KT7dw-0008Mc-Oo for bug-gnu-emacs@gnu.org; Wed, 13 Aug 2008 00:07:28 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KT7dv-0008MQ-Eq for bug-gnu-emacs@gnu.org; Wed, 13 Aug 2008 00:07:28 -0400 Original-Received: from [199.232.76.173] (port=39467 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KT7dv-0008MN-6z for bug-gnu-emacs@gnu.org; Wed, 13 Aug 2008 00:07:27 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:38310) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KT7du-000385-O2 for bug-gnu-emacs@gnu.org; Wed, 13 Aug 2008 00:07:27 -0400 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m7D47OHJ031351; Tue, 12 Aug 2008 21:07:25 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.13.8/8.13.8/Submit) id m7D3o4aB025026; Tue, 12 Aug 2008 20:50:04 -0700 X-Loop: don@donarmstrong.com Resent-From: Chong Yidong Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Wed, 13 Aug 2008 03:50:04 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 679 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Original-Received: via spool by 679-submit@emacsbugs.donarmstrong.com id=B679.121859895623234 (code B ref 679); Wed, 13 Aug 2008 03:50:04 +0000 Original-Received: (at 679) by emacsbugs.donarmstrong.com; 13 Aug 2008 03:42:36 +0000 Original-Received: from furry (c-24-63-201-57.hsd1.ma.comcast.net [24.63.201.57]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m7D3gW7O023228 for <679@emacsbugs.donarmstrong.com>; Tue, 12 Aug 2008 20:42:33 -0700 Original-Received: by furry (Postfix, from userid 1000) id E12E7C054; Tue, 12 Aug 2008 23:42:26 -0400 (EDT) X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Resent-Date: Wed, 13 Aug 2008 00:07:28 -0400 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:19366 Archived-At: Hi Edward, Could you take a look at this bug report? Thanks. --------------- In json.el, the 'json-read-number' function is intended to read the textual representation of Javascript numbers. (defun json-read-number () "Read the JSON number following point. N.B.: Only numbers which can fit in Emacs Lisp's native number representation will be parsed correctly." (if (char-equal (json-peek) ?-) (progn (json-advance) (- 0 (json-read-number))) (if (looking-at "[0-9]+\\([.][0-9]+\\)?\\([eE][+-]?[0-9]+\\)?") (progn (goto-char (match-end 0)) (string-to-number (match-string 0))) (signal 'json-number-format (list (point)))))) The Javascript spec (http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Literals#Floating-Point_Literals) says the following about floating-point numbers: | A floating-point literal can have the following parts: | | * A decimal integer which can be signed (preceded by "+" or "-"), | * A decimal point ("."), | * A fraction (another decimal number), | * An exponent. | | The exponent part is an "e" or "E" followed by an integer, which can | be signed (preceded by "+" or "-"). A floating-point literal must have | at least one digit and either a decimal point or "e" (or "E"). This means that 1. is a valid floating point-literal per the spec, but the regular expression above does not match the complete text---the regular expression requires digits after the decimal point. This ends up matched as a simple integer, leaving the decimal point in the input stream and causing a later syntax error. Similarly .1 is a valid floating point-literal illegal that Emacs rejects, because the regular expression requires digits before the decimal point. Testing with the error console in Firefox confirms that the two examples above are valid syntax. The parser function needs to be fixed to handle the complete syntax.