From 43027148cd2f672b5071f6317d1707a4f3cd9c85 Mon Sep 17 00:00:00 2001 From: Sohum Banerjea Date: Thu, 1 Aug 2024 16:56:16 +1000 Subject: [PATCH] fix elfeed-curl--queue-consolidate to maintain the same shape spec MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit under the old implementation, elfeed-curl--queue-consolidate wasn't idempotent — if you called it on a consolidated queue, it would continue to add list layers around the consolidated entry. this would then cause wrong-type-argument errors later when calling make-process to run curl. --- elfeed-curl.el | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/elfeed-curl.el b/elfeed-curl.el index c801696..b2467a1 100644 --- a/elfeed-curl.el +++ b/elfeed-curl.el @@ -458,11 +458,21 @@ results will not." method data)))) +(defun elfeed-curl--queue-right-shape (queue condition) + (dolist (item queue) + (unless (and (listp item) + (or (stringp (car item)) + (and (listp (car item)) + (cl-every #'stringp (car item))))) + (signal 'wrong-type-argument (list condition item)))) + ) + (defun elfeed-curl--queue-consolidate (queue-in) "Group compatible requests together and return a new queue. Compatible means the requests have the same protocol, domain, port, headers, method, and body, allowing them to be used safely in the same curl invocation." + (elfeed-curl--queue-right-shape queue-in 'consolidate-input-queue-wrong-shape) (let ((table (make-hash-table :test 'equal)) (keys ()) (queue-out ())) @@ -474,13 +484,14 @@ in the same curl invocation." (dolist (key (nreverse keys)) (let ((entry (gethash key table))) (when entry - (let ((rotated (list (nreverse (cl-mapcar #'car entry)) - (nreverse (cl-mapcar #'cadr entry)) + (let ((rotated (list (nreverse (flatten-tree (cl-mapcar #'car entry))) + (nreverse (flatten-tree (cl-mapcar #'cadr entry))) (cl-caddar entry) (elt (car entry) 3) (elt (car entry) 4)))) (push rotated queue-out) (setf (gethash key table) nil))))) + (elfeed-curl--queue-right-shape queue-out 'consolidate-output-queue-wrong-shape) (nreverse queue-out))) (defun elfeed-curl--queue-wrap (cb)