From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id kK6VNfxrTmISTwAAgWs5BA (envelope-from ) for ; Thu, 07 Apr 2022 06:43:40 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id sEoeMvxrTmIxEAEAauVa8A (envelope-from ) for ; Thu, 07 Apr 2022 06:43:40 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 1A97D243F7 for ; Thu, 7 Apr 2022 06:43:40 +0200 (CEST) Received: from localhost ([::1]:51186 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncJze-0008P9-Vz for larch@yhetil.org; Thu, 07 Apr 2022 00:43:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44692) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncJSD-0000wa-6U for emacs-orgmode@gnu.org; Thu, 07 Apr 2022 00:09:05 -0400 Received: from burlywood.elm.relay.mailchannels.net ([23.83.212.26]:21330) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncJSA-0006bh-W7 for emacs-orgmode@gnu.org; Thu, 07 Apr 2022 00:09:04 -0400 X-Sender-Id: dreamhost|x-authsender|arensb@ooblick.com Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 100721214FE for ; Thu, 7 Apr 2022 04:08:59 +0000 (UTC) Received: from pdx1-sub0-mail-a314.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 92F1F121409 for ; Thu, 7 Apr 2022 04:08:58 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1649304538; a=rsa-sha256; cv=none; b=HNBPAPe6kWqy+C8ZJs28klArw2GHDBIlS5WfWMUmfJ0xB/OKnvAZo97HjixsTEVW8J7rP6 SgIyTt3wwT8J0BgcebVKEWxquo43PJawWxZo8f2lBcThJIg5H/LfCWRSOqvnNj2o3TLrML SST6f8TYHxDdZ9za/D7GDmVNjVckwiqEVQJSaKw4MoRmrJ8bDGB525Cu5XfbJT0xVUbMFZ aMInoLFrW6AprQhPlsyY3IAWDU5Cv4Tz/6KrXXmaaM271o1/RsaTppCj5/zA8JtpWs3vhi TME+yBqXmyKRTY2vd6hZGZXEIr7Nky/VNpSFfzp/RTivd6nLW35drpdMTz6J7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1649304538; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: dkim-signature; bh=X74e1W//zKE+hzi+yw6HD5P/xZ/GuAEJXxn9cSlM06A=; b=p+PF18Z4wn+P1LmLcbnb3qL8yiZFdhFLKB6Tu5JUhTz42qTm/QowlVbU9yXTNrnFp2UfT8 ClxBqkSlMi6K8FyTfBeZePfdSy3UH+6INGgLw16b6ySVdANEifwT4TfogvQ3NSLM9MNOpp CeDQYZWV1GpzBAkSwk5iS8kE19dWuhHRMMcuWyUYrEYnMXuNfqmott+EOl/DhOrKSw9oDX KHm8u6omS7CGZ8TM3Pb6Vdj1RXdvCJ3Qk0zlE17Wc3uV2JjUOR5zoT/LJbAvIa96sofi2f ebtNLtt0n/Qiz+2/l5r3KSNP3eSWl9T5BwpePPXARvSNsarEFCWRYM1Xw1ToSw== ARC-Authentication-Results: i=1; rspamd-786f77c8d-q4cbq; auth=pass smtp.auth=dreamhost smtp.mailfrom=arensb@ooblick.com X-Sender-Id: dreamhost|x-authsender|arensb@ooblick.com Received: from pdx1-sub0-mail-a314.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.96.96.54 (trex/6.7.1); Thu, 07 Apr 2022 04:08:59 +0000 X-MC-Relay: Junk X-MailChannels-SenderId: dreamhost|x-authsender|arensb@ooblick.com X-MailChannels-Auth-Id: dreamhost X-Trouble-Army: 54b1d77b47f057c6_1649304538828_1209997226 X-MC-Loop-Signature: 1649304538828:3945028628 X-MC-Ingress-Time: 1649304538827 Received: from [192.168.3.67] (pool-74-96-142-229.washdc.fios.verizon.net [74.96.142.229]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: arensb@ooblick.com) by pdx1-sub0-mail-a314.dreamhost.com (Postfix) with ESMTPSA id 4KYnty1bvgz3b for ; Wed, 6 Apr 2022 21:08:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ooblick.com; s=dreamhost; t=1649304538; bh=X74e1W//zKE+hzi+yw6HD5P/xZ/GuAEJXxn9cSlM06A=; h=Content-Type:Date:To:From:Subject; b=RfMcp/8RlgNKY7D/soywfBlcpBHb7eTEDUtFQoI37Pbz83yhYx3JJXnyuDqYNhtLq F9tcbXHJNp9gW0sAHOQBH//MIky5pQ5t137rngFGLX6hcyntnbngo/ElT/5jDkecy+ oKAMeWlNzaj+T7pr9r2Do9wrSn0/2qYGTxy+ChlzPhW2nU2BFDUcmxjOnbIvBwAZ9D 45efKxl39RKlUGFS9EOHZljrKvqGI829yzDRfAmvwPq5pIJNRNfGipEF/31lEAzhC0 SsG2ttEAfXMIJ1LyLSRzRswO72zxb81wwqYWF0u64FUR3QbAhElX9iU3cEXw9LlDqi Dun3SLdyQ7AHA== Content-Type: multipart/mixed; boundary="------------FWQZwFbA8ANx1gz2WzFfDlTu" Message-ID: Date: Thu, 7 Apr 2022 00:08:56 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Content-Language: en-US To: emacs-orgmode@gnu.org From: Andrew Arensburger Subject: Patch: bug in template expansion in org-fill-template Received-SPF: pass client-ip=23.83.212.26; envelope-from=arensb@ooblick.com; helo=burlywood.elm.relay.mailchannels.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 07 Apr 2022 00:42:54 -0400 X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1649306620; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=X74e1W//zKE+hzi+yw6HD5P/xZ/GuAEJXxn9cSlM06A=; b=JR9yMW40o5imUWZTbt/RNIEC2/Cw61VvDZbKy0rEN76PCCaX6KSduxQOq3aOpbYvfpCSe+ e44PSa5ue5mHZPOlDBC0p1Smv0TlMKFJqKPaMK+ldfcSnLCUCl0w0AdETFNB4eFxb0y+hJ WeO+L7VSRPVWBnwy89JGnZmmII7/m9zSMM0f9K4o0Gwu25gpGa14Jabm7f+hEJ9vR51WSh 5Gc9e+LezpqA1OYrC2J0KM0C5rYOaWu+7zuGOW7u1m4fnbvu0qjUz0Msa5Ch10r++DAhnF TAw3WkS8k0FvQtLat+fcO9Cy5D2NVmkzOFs8xIa7jMgxswvPXLtXToa5Su8JBQ== ARC-Seal: i=2; s=key1; d=yhetil.org; t=1649306620; a=rsa-sha256; cv=pass; b=SjMxdZAaq0EybBHMbZdNPXjFX2pQGI01SOH/89I2qSbJty0U2BGZlQyWp8mfwT9pMv390I TPW9cX/qv4H/7oS67WPl2QNOyw00k+K6BONnw5kOAh34Go7tauJ32E+vLDzbbEYn/r8NDQ aMwk17stytanC5C1rnkWPaQAPwBWsK8+wRPxabpYQvGRU1Bmq+ygq8Ma7cPFSNk9TJPRBa ZKmbf+AkyxfBhRZfYWB5xydlj3ojTTiiW5ns6yteEB9EJ0gIkMY1bfsc+5lw7BwxLi8HH1 VJEvqJzNF2VfnAyAkJjsHByiH145K/BkxIIRuxTsfqi1T9C9sMwV1VaWS9T/KQ== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=ooblick.com header.s=dreamhost header.b="RfMcp/8R"; arc=pass ("mailchannels.net:s=arc-2022:i=1"); dmarc=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -8.37 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=ooblick.com header.s=dreamhost header.b="RfMcp/8R"; arc=pass ("mailchannels.net:s=arc-2022:i=1"); dmarc=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 1A97D243F7 X-Spam-Score: -8.37 X-Migadu-Scanner: scn0.migadu.com X-TUID: do3auT3Qc6vg This is a multi-part message in MIME format. --------------FWQZwFbA8ANx1gz2WzFfDlTu Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit There appears to be a bug in `org-fill-template' (in lisp/org-macs.el): keys to be expanded are sorted by increasing length, so that "noweb" is processed before "noweb-ref". As a result, if a template includes "%noweb-ref", `org-fill-template' will expand it as "%{noweb}-ref" rather than "%{noweb-ref}". As far as I can tell, this bug has existed since `org-fill-template' was added, in e8ef16306ca56af2dceb9e2be0b57c930e9b5584 . I tried to trace it as back as I could, to see whether there was a good reason for sorting keys this way, but couldn't find one. I'm including a patch with a test to find buggy behavior, and another to fix it. --------------FWQZwFbA8ANx1gz2WzFfDlTu Content-Type: text/x-patch; charset=UTF-8; name="0001-test-org-macs.el-Add-test-for-template-expansion-bug.patch" Content-Disposition: attachment; filename*0="0001-test-org-macs.el-Add-test-for-template-expansion-bug.pa"; filename*1="tch" Content-Transfer-Encoding: base64 RnJvbSBjNTJjZTYzMWZiYzJmODgzNmUxMGZmNDE4OTU4OTI4MzliMzQ5ZGEzIE1vbiBTZXAg MTcgMDA6MDA6MDAgMjAwMQpGcm9tOiBBbmRyZXcgQXJlbnNidXJnZXIgPGFyZW5zYj4KRGF0 ZTogV2VkLCA2IEFwciAyMDIyIDE0OjU4OjQ0IC0wNDAwClN1YmplY3Q6IFtQQVRDSCAxLzJd IHRlc3Qtb3JnLW1hY3MuZWw6IEFkZCB0ZXN0IGZvciB0ZW1wbGF0ZS1leHBhbnNpb24gYnVn LgoKKiB0ZXN0aW5nL2xpc3AvdGVzdC1vcmctbWFjcy5lbCAoZXJ0LWRlZnRlc3QgdGVzdC1v cmcvZmlsbC10ZW1wbGF0ZSk6ClRoZXJlIGlzIGEgYnVnIGluIGBvcmctZ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orICAgICAgICAgICAgKG9yZy1maWxsLXRlbXBsYXRl ICIldmFyLWxvbmciCisgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJygoInZhciIg LiAiYnJva2VuIikKKyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICgidmFyLWxv bmciIC4gIndvcmtpbmciKSkpKSkpCiAMCiA7OzsgVGltZQogCi0tIAoyLjI1LjEKCg== --------------FWQZwFbA8ANx1gz2WzFfDlTu Content-Type: text/x-patch; charset=UTF-8; name="0002-org-macs.el-Fix-template-expansion.patch" Content-Disposition: attachment; filename="0002-org-macs.el-Fix-template-expansion.patch" Content-Transfer-Encoding: base64 RnJvbSBhYjJhZDk0N2JjNzQxY2E0MjcwMGRmYTA1YmIyY2UwMDkwM2Y4ZGI4IE1vbiBTZXAg MTcgMDA6MDA6MDAgMjAwMQpGcm9tOiBBbmRyZXcgQXJlbnNidXJnZXIgPGFyZW5zYj4KRGF0 ZTogV2VkLCA2IEFwciAyMDIyIDE3OjAyOjE5IC0wNDAwClN1YmplY3Q6IFtQQVRDSCAyLzJd IG9yZy1tYWNzLmVsOiBGaXggdGVtcGxhdGUgZXhwYW5zaW9uLgoKKiBsaXNwL29yZy1tYWNz LmVsIChvcmctZmlsbC10ZW1wbGF0ZSk6IEZpeCBhIGJ1ZyBpbiB0ZW1wbGF0ZQpleHBhbnNp b246IGlmIG9uZSBrZXkgaXMgYSBzdWJzdHJpbmcgb2YgYW5vdGhlciBrZXkgKGxpa2UgIm5v d2ViIiBhbmQKIm5vd2ViLXJlZiIsIG9yICJ0YW5nbGUiIGFuZCAidGFuZ2xlLW1vZGUiKSwg dGhlIHNlY29uZCBrZXkgd291bGRuJ3QKZ2V0IGV4cGFuZGVkIHByb3Blcmx5LiAgVGhlIHBy b2JsZW0gd2FzIHRoYXQga2V5cyB3ZXJlIHByb2Nlc3NlZCBpbgpvcmRlciBvZiBpbmNyZWFz aW5nIGxlbmd0aDsgdGhleSBhcmUgbm93IHNvcnRlZCBp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