From unknown Thu Aug 21 14:53:25 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74848: [PATCH] calendar: check for presuppositions in `calendar-date-is-valid-p' Resent-From: Richard Lawrence Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 13 Dec 2024 12:03:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 74848 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 74848@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.17340913698960 (code B ref -1); Fri, 13 Dec 2024 12:03:01 +0000 Received: (at submit) by debbugs.gnu.org; 13 Dec 2024 12:02:49 +0000 Received: from localhost ([127.0.0.1]:41866 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tM4Nc-0002KR-CB for submit@debbugs.gnu.org; Fri, 13 Dec 2024 07:02:49 -0500 Received: from lists.gnu.org ([209.51.188.17]:42138) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tM4NY-0002KD-T6 for submit@debbugs.gnu.org; Fri, 13 Dec 2024 07:02:46 -0500 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 1tM4NX-0007Sv-Tj for bug-gnu-emacs@gnu.org; Fri, 13 Dec 2024 07:02:44 -0500 Received: from fout-a3-smtp.messagingengine.com ([103.168.172.146]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tM4NW-00089f-3Q for bug-gnu-emacs@gnu.org; Fri, 13 Dec 2024 07:02:43 -0500 Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfout.phl.internal (Postfix) with ESMTP id 775E11384156 for ; Fri, 13 Dec 2024 07:02:39 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Fri, 13 Dec 2024 07:02:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= recursewithless.net; h=cc:content-type:content-type:date:date :from:from:in-reply-to:message-id:mime-version:reply-to:subject :subject:to:to; s=fm3; t=1734091359; x=1734177759; bh=vAvkamcwai 46rvd8rzMvto75Fyq2cTJjPlSJ8ZuTbQI=; b=qnRqCOlCT3LVR14N8NmG49+DCb 8XlmccR1lVanVRZCrnXErqDn3ewZ01OLvg+kEXHuMkIjgv894E7rKsXQDPTkH7sE lKMKKguuW98MaVeHNUKWsYXsK7CqZjWkHJj6iOwRnmJs47m3gYRlsrCBRMUSAzKJ NcxecUORtTmbVI1glYt8ibqLf/zId1sHIoA2u7xJFon+50nWA2fUWUnvi+0qCHCR nAm5HHxz6ulBX3mcuupCD+4HkMMUuxITgKdoA3KAu6OPfkzUd0pk1Clq1KCtk5pQ Hr7/1yuULp4dD2kZO4bsMy8WnTNnSEMHJlPZSde2jMJrJ5Lu3QHCWeX/68ag== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1734091359; x= 1734177759; bh=vAvkamcwai46rvd8rzMvto75Fyq2cTJjPlSJ8ZuTbQI=; b=n F4frzoaOa4LH54SdfozHZ9oVoS7bOsOArngTUddcz18RQcZkRIelOoB+sc5DjTRj ASRZOlNuKCRN5S/C/DOTmOKLFl0IMo/2BfQ3fZS9ZqVhIwUFqV64Mni3SyXdLxPR JzzPt0GCVf+n+hcSQN8DbSJCJUEkTpPCoCcHLhums8ec0Z9+a1ROW3iJ2IbQVY7j Mh/BP/+obuEjinOGJlhpxJsfN3BXuIq8QXGzToEXkYZiG+bUjRbQc0GmVgAE0SQI mvWOwmP2h+s+cSYLFDmk+RFKeuIahctdeZxMQTiKhl7YxDSjqV+xu5JoBqodYTYZ WCAigOtWUhj1YyuZwPa1w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrkeejgdefhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkf ggtgesmhdtreertddttdenucfhrhhomheptfhitghhrghrugcunfgrfihrvghntggvuceo rhiflhesrhgvtghurhhsvgifihhthhhlvghsshdrnhgvtheqnecuggftrfgrthhtvghrnh epieduleffheekhfeihfetgeekveelieetvefhteeggefgudevueejveeghfekleelnecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprhiflhesrh gvtghurhhsvgifihhthhhlvghsshdrnhgvthdpnhgspghrtghpthhtohepuddpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepsghughdqghhnuhdqvghmrggtshesghhnuhdroh hrgh X-ME-Proxy: Feedback-ID: if7394488:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 13 Dec 2024 07:02:38 -0500 (EST) From: Richard Lawrence Date: Fri, 13 Dec 2024 13:02:36 +0100 Message-ID: <87o71fpz8j.fsf@ohm.mail-host-address-is-not-set> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=103.168.172.146; envelope-from=rwl@recursewithless.net; helo=fout-a3-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.6 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.6 (--) --=-=-= Content-Type: text/plain Tags: patch Tags: patch Hi all, Here is a patch to make calendar-date-is-valid-p return nil, instead of signaling an error, when it is passed a value that isn't a list of the form (MONTH DAY YEAR). This (a) makes the function a proper predicate, as its name suggests, which (b) is necessary in some of the new iCalendar code I've been working on (to be posted soon). (I've deleted the build information about the Emacs I'm sending from, because it is different from Emacs master, against which the patch is formatted.) This is my first time submitting a patch with submit-emacs-patch, so please let me know if I did anything wrong. Thanks! Richard --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-calendar-check-for-presuppositions-in-calendar-date-.patch >From 794c27fac28260498b26e1cb60aa7576ca487f08 Mon Sep 17 00:00:00 2001 From: Richard Lawrence Date: Fri, 13 Dec 2024 10:41:02 +0100 Subject: [PATCH] calendar: check for presuppositions in `calendar-date-is-valid-p' This function previously would signal an error if passed a value which was not a three-element list of integers, making it not unusable as a predicate for valid date values. --- lisp/calendar/calendar.el | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) 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." -- 2.39.5 --=-=-=-- From unknown Thu Aug 21 14:53:25 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74848: [PATCH] calendar: check for presuppositions in `calendar-date-is-valid-p' Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 14 Dec 2024 11:07: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 To: Richard Lawrence Cc: 74848@debbugs.gnu.org Received: via spool by 74848-submit@debbugs.gnu.org id=B74848.173417437010893 (code B ref 74848); Sat, 14 Dec 2024 11:07:01 +0000 Received: (at 74848) by debbugs.gnu.org; 14 Dec 2024 11:06:10 +0000 Received: from localhost ([127.0.0.1]:45712 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tMPyL-0002pa-W3 for submit@debbugs.gnu.org; Sat, 14 Dec 2024 06:06:10 -0500 Received: from eggs.gnu.org ([209.51.188.92]:57986) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tMPyK-0002pM-9i for 74848@debbugs.gnu.org; Sat, 14 Dec 2024 06:06:09 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMPyE-0004dW-Vv; Sat, 14 Dec 2024 06:06:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=lXIriBh6AwTzSO3he+q7b0vO0j+pWL5TF+BHTcCBAlg=; b=hllPRjaRXD49 wEpUiXkkgKoP11K7/VY9cLusTyfoLltZVaRHhR/S9thM5IBuOCnLpScdoAfZj/KRuS4f5VT/CzC/4 XOBXl4hQt0bY4T+m43pr4Lu7udS3WhyKtrGlEtNqoXho+8P10883BhzIFi1TF0DJHsZrjhjUASlTG kc56kc/pfR7ndpzQh/kkpZucb24Q4Ewkp73SEJzqQjI7RqmG/0YTuLo/wpA8bshMMQP7TKSHkLwhx QeYq4CJn+wtpgrAsde7TdXulUOk0m/C4OS9Cz2fMR3SmiSAbw6vNApN7GKSCwGmVV/IYkBZn3hOva oERcs/2KTuSuxm5GKJUo8A==; Date: Sat, 14 Dec 2024 13:06:00 +0200 Message-Id: <86cyhuv813.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <87o71fpz8j.fsf@ohm.mail-host-address-is-not-set> (message from Richard Lawrence on Fri, 13 Dec 2024 13:02:36 +0100) References: <87o71fpz8j.fsf@ohm.mail-host-address-is-not-set> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Richard Lawrence > Date: Fri, 13 Dec 2024 13:02:36 +0100 > > Here is a patch to make calendar-date-is-valid-p return nil, instead of > signaling an error, when it is passed a value that isn't a list of the > form (MONTH DAY YEAR). > > This (a) makes the function a proper predicate, as its name suggests, > which (b) is necessary in some of the new iCalendar code I've been > working on (to be posted soon). Thanks. > This is my first time submitting a patch with submit-emacs-patch, so > please let me know if I did anything wrong. 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. P.S. I presume you've run the relevant parts of the test suite and verified that they still succeed. If not, please do. From unknown Thu Aug 21 14:53:25 2025 X-Loop: help-debbugs@gnu.org Subject: bug#74848: [PATCH] calendar: check for presuppositions in `calendar-date-is-valid-p' 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 To: Eli Zaretskii Cc: 74848@debbugs.gnu.org Received: via spool by 74848-submit@debbugs.gnu.org id=B74848.173417878023650 (code B ref 74848); Sat, 14 Dec 2024 12:20:01 +0000 Received: (at 74848) by debbugs.gnu.org; 14 Dec 2024 12:19:40 +0000 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 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 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) 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 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 14 Dec 2024 07:19:22 -0500 (EST) From: Richard Lawrence In-Reply-To: <86cyhuv813.fsf@gnu.org> References: <87o71fpz8j.fsf@ohm.mail-host-address-is-not-set> <86cyhuv813.fsf@gnu.org> Date: Sat, 14 Dec 2024 13:19:19 +0100 Message-ID: <875xnmpid4.fsf@recursewithless.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: 0.6 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.4 (/) --=-=-= 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 --=-=-=-- From unknown Thu Aug 21 14:53:25 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Richard Lawrence Subject: bug#74848: closed (Re: bug#74848: [PATCH] calendar: check for presuppositions in `calendar-date-is-valid-p') Message-ID: References: <861pyav3es.fsf@gnu.org> <87o71fpz8j.fsf@ohm.mail-host-address-is-not-set> X-Gnu-PR-Message: they-closed 74848 X-Gnu-PR-Package: emacs X-Gnu-PR-Keywords: patch Reply-To: 74848@debbugs.gnu.org Date: Sat, 14 Dec 2024 12:47:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1734180422-28954-1" This is a multi-part message in MIME format... ------------=_1734180422-28954-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #74848: [PATCH] calendar: check for presuppositions in `calendar-date-is-va= lid-p' which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 74848@debbugs.gnu.org. --=20 74848: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D74848 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1734180422-28954-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 74848-done) by debbugs.gnu.org; 14 Dec 2024 12:46:05 +0000 Received: from localhost ([127.0.0.1]:45839 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tMRX2-0007VC-7y for submit@debbugs.gnu.org; Sat, 14 Dec 2024 07:46:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59444) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tMRWt-0007UU-VY for 74848-done@debbugs.gnu.org; Sat, 14 Dec 2024 07:46:02 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tMRWn-0001qf-Ni; Sat, 14 Dec 2024 07:45:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=lxB/kY7vqDV/VDf+SxL/qBCu+OCF8+srVkPT+qYA/4s=; b=qljTOcMW2s5F mjkzvKXxiGmL540jqnr7WvWBV/sF7BpYhx7OT6DxgLsqVZj+uhg1LLQF+Ei7sps6/2e3znUeIgYqs g/8SVhvmbYiTU4EjwFWUesI04nt9N/Z7PnKGXeFXlkDnRxVHwtGuw6LhkWsmlT5AZDPPHDdKtHTdG h6TFDLKIwUvMIVyay4B2QtMTTLy+RKOoNSdY1LEEdsi5Ai8sMth3HYypvZ26Qq57mq9bW14W1zCwB ZWW8eFnoiazvsBj5tQGUna0q8asY2M1H5V5pqAHvi0P9G/7KTa5Z3ZjZEzZFPsfd516Ez4p5t+bA3 6eh9dvZ5y5ZZqXYzukVXKQ==; Date: Sat, 14 Dec 2024 14:45:47 +0200 Message-Id: <861pyav3es.fsf@gnu.org> From: Eli Zaretskii To: Richard Lawrence In-Reply-To: <875xnmpid4.fsf@recursewithless.net> (message from Richard Lawrence on Sat, 14 Dec 2024 13:19:19 +0100) Subject: Re: bug#74848: [PATCH] calendar: check for presuppositions in `calendar-date-is-valid-p' References: <87o71fpz8j.fsf@ohm.mail-host-address-is-not-set> <86cyhuv813.fsf@gnu.org> <875xnmpid4.fsf@recursewithless.net> X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 74848-done Cc: 74848-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Richard Lawrence > Cc: 74848@debbugs.gnu.org > Date: Sat, 14 Dec 2024 13:19:19 +0100 > > 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. Thanks, installed on the master branch, and closing the bug. I needed to tweak the commit log message somewhat; please see how I changed it and try to follow these conventions in the future. ------------=_1734180422-28954-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 13 Dec 2024 12:02:49 +0000 Received: from localhost ([127.0.0.1]:41866 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tM4Nc-0002KR-CB for submit@debbugs.gnu.org; Fri, 13 Dec 2024 07:02:49 -0500 Received: from lists.gnu.org ([209.51.188.17]:42138) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tM4NY-0002KD-T6 for submit@debbugs.gnu.org; Fri, 13 Dec 2024 07:02:46 -0500 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 1tM4NX-0007Sv-Tj for bug-gnu-emacs@gnu.org; Fri, 13 Dec 2024 07:02:44 -0500 Received: from fout-a3-smtp.messagingengine.com ([103.168.172.146]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tM4NW-00089f-3Q for bug-gnu-emacs@gnu.org; Fri, 13 Dec 2024 07:02:43 -0500 Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfout.phl.internal (Postfix) with ESMTP id 775E11384156 for ; Fri, 13 Dec 2024 07:02:39 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Fri, 13 Dec 2024 07:02:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= recursewithless.net; h=cc:content-type:content-type:date:date :from:from:in-reply-to:message-id:mime-version:reply-to:subject :subject:to:to; s=fm3; t=1734091359; x=1734177759; bh=vAvkamcwai 46rvd8rzMvto75Fyq2cTJjPlSJ8ZuTbQI=; b=qnRqCOlCT3LVR14N8NmG49+DCb 8XlmccR1lVanVRZCrnXErqDn3ewZ01OLvg+kEXHuMkIjgv894E7rKsXQDPTkH7sE lKMKKguuW98MaVeHNUKWsYXsK7CqZjWkHJj6iOwRnmJs47m3gYRlsrCBRMUSAzKJ NcxecUORtTmbVI1glYt8ibqLf/zId1sHIoA2u7xJFon+50nWA2fUWUnvi+0qCHCR nAm5HHxz6ulBX3mcuupCD+4HkMMUuxITgKdoA3KAu6OPfkzUd0pk1Clq1KCtk5pQ Hr7/1yuULp4dD2kZO4bsMy8WnTNnSEMHJlPZSde2jMJrJ5Lu3QHCWeX/68ag== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1734091359; x= 1734177759; bh=vAvkamcwai46rvd8rzMvto75Fyq2cTJjPlSJ8ZuTbQI=; b=n F4frzoaOa4LH54SdfozHZ9oVoS7bOsOArngTUddcz18RQcZkRIelOoB+sc5DjTRj ASRZOlNuKCRN5S/C/DOTmOKLFl0IMo/2BfQ3fZS9ZqVhIwUFqV64Mni3SyXdLxPR JzzPt0GCVf+n+hcSQN8DbSJCJUEkTpPCoCcHLhums8ec0Z9+a1ROW3iJ2IbQVY7j Mh/BP/+obuEjinOGJlhpxJsfN3BXuIq8QXGzToEXkYZiG+bUjRbQc0GmVgAE0SQI mvWOwmP2h+s+cSYLFDmk+RFKeuIahctdeZxMQTiKhl7YxDSjqV+xu5JoBqodYTYZ WCAigOtWUhj1YyuZwPa1w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrkeejgdefhecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkf ggtgesmhdtreertddttdenucfhrhhomheptfhitghhrghrugcunfgrfihrvghntggvuceo rhiflhesrhgvtghurhhsvgifihhthhhlvghsshdrnhgvtheqnecuggftrfgrthhtvghrnh epieduleffheekhfeihfetgeekveelieetvefhteeggefgudevueejveeghfekleelnecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprhiflhesrh gvtghurhhsvgifihhthhhlvghsshdrnhgvthdpnhgspghrtghpthhtohepuddpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepsghughdqghhnuhdqvghmrggtshesghhnuhdroh hrgh X-ME-Proxy: Feedback-ID: if7394488:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 13 Dec 2024 07:02:38 -0500 (EST) From: Richard Lawrence To: bug-gnu-emacs@gnu.org Subject: [PATCH] calendar: check for presuppositions in `calendar-date-is-valid-p' Date: Fri, 13 Dec 2024 13:02:36 +0100 Message-ID: <87o71fpz8j.fsf@ohm.mail-host-address-is-not-set> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=103.168.172.146; envelope-from=rwl@recursewithless.net; helo=fout-a3-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.6 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.6 (--) --=-=-= Content-Type: text/plain Tags: patch Tags: patch Hi all, Here is a patch to make calendar-date-is-valid-p return nil, instead of signaling an error, when it is passed a value that isn't a list of the form (MONTH DAY YEAR). This (a) makes the function a proper predicate, as its name suggests, which (b) is necessary in some of the new iCalendar code I've been working on (to be posted soon). (I've deleted the build information about the Emacs I'm sending from, because it is different from Emacs master, against which the patch is formatted.) This is my first time submitting a patch with submit-emacs-patch, so please let me know if I did anything wrong. Thanks! Richard --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-calendar-check-for-presuppositions-in-calendar-date-.patch >From 794c27fac28260498b26e1cb60aa7576ca487f08 Mon Sep 17 00:00:00 2001 From: Richard Lawrence Date: Fri, 13 Dec 2024 10:41:02 +0100 Subject: [PATCH] calendar: check for presuppositions in `calendar-date-is-valid-p' This function previously would signal an error if passed a value which was not a three-element list of integers, making it not unusable as a predicate for valid date values. --- lisp/calendar/calendar.el | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) 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." -- 2.39.5 --=-=-=-- ------------=_1734180422-28954-1--