From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Richard Lawrence Newsgroups: gmane.emacs.bugs Subject: bug#74848: [PATCH] calendar: check for presuppositions in `calendar-date-is-valid-p' Date: Sat, 14 Dec 2024 13:19:19 +0100 Message-ID: <875xnmpid4.fsf@recursewithless.net> References: <87o71fpz8j.fsf@ohm.mail-host-address-is-not-set> <86cyhuv813.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10339"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 74848@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 14 13:20:25 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tMR8B-0002XA-Fp for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 14 Dec 2024 13:20:24 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tMR7v-0002yr-2K; Sat, 14 Dec 2024 07:20:07 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMR7r-0002wc-SB for bug-gnu-emacs@gnu.org; Sat, 14 Dec 2024 07:20:04 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tMR7r-00028W-Cs for bug-gnu-emacs@gnu.org; Sat, 14 Dec 2024 07:20:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=tNCcr5hBFz4m8EGPnXNBhWYKrz8WnAvFBbsRnC6hzhk=; b=s80gbFwSBtdeajlBVBxoyGthg3RVusFiVEcYka6a+tMMxWjRVGhNaxweqx/FKu99SLvwdFqwtdb1l3bZA0A5N3xPVIMijFxa967V5P0BcBs86pR/yiKRe97LBDe+BcMi17ACE5q3JELxpt1LeY8RNfmiuZODtMH2C0lcY2DyO8l18SZ6aMW6fWa+LoqRIcpAiQxnSQ6JoL6+y3Nk2jCTTSxUnCgjCdXIW/qGP0LJeuUv4zdcI5HyVARc2H6FupErDynahMbpaGYpLTjoGkS3RHylyuGudCrpnNjAD+8t8qGp5ApzXbqgZHuNM8Gh9cLKF4cPlIs3z6Uc4bT9wziqpw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tMR7p-0006AB-Uh for bug-gnu-emacs@gnu.org; Sat, 14 Dec 2024 07:20:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Richard Lawrence Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 14 Dec 2024 12:20:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74848 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 74848-submit@debbugs.gnu.org id=B74848.173417878023650 (code B ref 74848); Sat, 14 Dec 2024 12:20:01 +0000 Original-Received: (at 74848) by debbugs.gnu.org; 14 Dec 2024 12:19:40 +0000 Original-Received: from localhost ([127.0.0.1]:45802 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tMR7U-00069N-3P for submit@debbugs.gnu.org; Sat, 14 Dec 2024 07:19:40 -0500 Original-Received: from [202.12.124.157] (port=60281 helo=fhigh-b6-smtp.messagingengine.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tMR7R-00068x-Fj for 74848@debbugs.gnu.org; Sat, 14 Dec 2024 07:19:38 -0500 Original-Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.stl.internal (Postfix) with ESMTP id 5F5C42540144; Sat, 14 Dec 2024 07:19:23 -0500 (EST) Original-Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Sat, 14 Dec 2024 07:19:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= recursewithless.net; h=cc:cc:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1734178763; x=1734265163; bh=tNCcr5hBFz4m8EGPnXNBhWYKrz8WnAvFBbsRnC6hzhk=; b= qsfLnqV77XStsDf7xgaKQQV5xY6TqkwRKOK3AYCyyECHfGk9QRU7/m1ENBz1qsoK ANI0b8bTJTGA7lcI6GAUk4C9pmEkKh+CnfKvGtLhvZZE+ljB21XtFR3CMGh8dSJy VwvAiWJPbCm324/xa8R09LfklL6OLIIgRrrGVCqmsH46cm/ZgLWCMz51LG1Qyvck zCJdmuwVy2UsLEZLE1EoJn7/zPiukW2GSMAx8BFs01ehgFWq4S4YPveQERyK6pCS L8EVhd5iyeRdrVpOl4AWmpikhCcb6jD5CkW85n1LjlTV3d1q2N/EDSbyGua7zGHe iAjTYxctcKwk7lO9Mea1rA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1734178763; x=1734265163; bh=tNCcr5hBFz4m8EGPnXNBhWYKrz8WnAvFBbs RnC6hzhk=; b=TQXayW9oPNwsySNnoIN1jqTgENjxmeD9T0JKFAYcnGdRGSVKnnl BTPznY872UFGrp1OU+UN80JsUrNM49yY0qWdOoiV14UMY3h5MbPbY6mJCTgJZBQV 1dTuw9WUF6T+u57CmwcO7FZdxFRlCVR4cGPiArYAmJl4jSP8Tcj4FcA3qp2O/aRl RQeNFhz6sTGKnCR+N72LuhkBsiwCKGvdKrw45XvneZUDxxXPseFe1zlJm0RYkss1 3e6VNFP5Iz2/dbTV9hvwIYNrzN8Hr5pgasWmSnWoIZaGwYpNYhnesDddtntdFXhU sJHatbx1k0CJR/dwgAACYV9ldNrdzTnmyQg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrkeelgdefjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefhvfevufgjfhffkfggtgesmhdtreertddttdenucfh rhhomheptfhitghhrghrugcunfgrfihrvghntggvuceorhiflhesrhgvtghurhhsvgifih hthhhlvghsshdrnhgvtheqnecuggftrfgrthhtvghrnhepfeduteehtdefkeduudeludff heetueegleethefgkefhhffhudegffehhfehvddunecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomheprhiflhesrhgvtghurhhsvgifihhthhhlvghs shdrnhgvthdpnhgspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpth htohepvghlihiisehgnhhurdhorhhgpdhrtghpthhtohepjeegkeegkeesuggvsggsuhhg shdrghhnuhdrohhrgh X-ME-Proxy: Feedback-ID: if7394488:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 14 Dec 2024 07:19:22 -0500 (EST) In-Reply-To: <86cyhuv813.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:297042 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: > The commit log message should include the file and the function(s) > where the changes are done, as well as a short description of the > changes. See CONTRIBUTE for more details, and see "git log" for the > examples of how we format commit log messages. Please don't forget to > mention the bug number in the commit log message. Woops, sorry, I did look at that file but I guess I missed that. New patch attached. > P.S. I presume you've run the relevant parts of the test suite and > verified that they still succeed. If not, please do. Oddly enough, unless I'm missing something, there don't seem to be any tests for calendar.el. There *are* a bunch of test files in test/lisp/calendar, but they are all for other files, not for calendar.el itself. The attached patch includes a new test file with a basic test of the predicate, and make check reveals no relevant problems. Best, Richard --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Check-for-presuppositions-in-calendar-date-is-valid-.patch >From 03be4ce15fbc4f3620bf332ab608b9abc0bf2500 Mon Sep 17 00:00:00 2001 From: Richard Lawrence Date: Fri, 13 Dec 2024 10:41:02 +0100 Subject: [PATCH] Check for presuppositions in `calendar-date-is-valid-p' Do not signal an error in `calendar-date-is-valid-p' if passed a value which is not a three-element list of integers. Signaling an error makes the function unusable as a predicate for valid date values. (Bug#74848) * lisp/calendar/calendar.el (calendar-date-is-valid-p): add the checks * test/lisp/calendar/calendar-tests.el (calendar-test-validity-predicate): test that the predicate returns nil for several invalid values --- lisp/calendar/calendar.el | 29 +++++++++++++----------- test/lisp/calendar/calendar-tests.el | 34 ++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 13 deletions(-) create mode 100644 test/lisp/calendar/calendar-tests.el diff --git a/lisp/calendar/calendar.el b/lisp/calendar/calendar.el index 345687d1775..7c883617aca 100644 --- a/lisp/calendar/calendar.el +++ b/lisp/calendar/calendar.el @@ -2459,19 +2459,22 @@ calendar-nongregorian-visible-p (defun calendar-date-is-valid-p (date) "Return t if DATE is a valid date." - (let ((month (calendar-extract-month date)) - (day (calendar-extract-day date)) - (year (calendar-extract-year date))) - (and (<= 1 month) (<= month 12) - ;; (calendar-read-date t) used to return a date with day = nil. - ;; Should not be valid (?), since many funcs prob assume integer. - ;; (calendar-read-date 'noday) returns (month year), which - ;; currently results in calendar-extract-year returning nil. - day year (<= 1 day) (<= day (calendar-last-day-of-month month year)) - ;; BC dates left as non-valid, to suppress errors from - ;; complex holiday algorithms not suitable for years BC. - ;; Note there are side effects on calendar navigation. - (<= 1 year)))) + (when (and (listp date) + (length= date 3)) + (let ((month (calendar-extract-month date)) + (day (calendar-extract-day date)) + (year (calendar-extract-year date))) + (and (integerp month) (integerp day) (integerp year) + (<= 1 month) (<= month 12) + ;; (calendar-read-date t) used to return a date with day = nil. + ;; Should not be valid (?), since many funcs prob assume integer. + ;; (calendar-read-date 'noday) returns (month year), which + ;; currently results in calendar-extract-year returning nil. + day year (<= 1 day) (<= day (calendar-last-day-of-month month year)) + ;; BC dates left as non-valid, to suppress errors from + ;; complex holiday algorithms not suitable for years BC. + ;; Note there are side effects on calendar navigation. + (<= 1 year))))) (defun calendar-date-equal (date1 date2) "Return t if the DATE1 and DATE2 are the same." diff --git a/test/lisp/calendar/calendar-tests.el b/test/lisp/calendar/calendar-tests.el new file mode 100644 index 00000000000..c41f14d3b54 --- /dev/null +++ b/test/lisp/calendar/calendar-tests.el @@ -0,0 +1,34 @@ +;;; calendar-tests.el --- tests for calendar/calendar.el -*- lexical-binding:t -*- + +;; Copyright (C) 2024 Free Software Foundation, Inc. + +;; Author: Richard Lawrence + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Code: + +(require 'ert) +(require 'calendar) + +(ert-deftest calendar-test-validity-predicate () + (should (eq (calendar-date-is-valid-p nil) nil)) + (should (eq (calendar-date-is-valid-p "invalid") nil)) + (should (eq (calendar-date-is-valid-p (list 1 2)) nil)) + (should (eq (calendar-date-is-valid-p (list 5 1 2025)) t))) + +(provide 'calendar-tests) +;;; calendar-tests.el ends here -- 2.39.5 --=-=-=--