From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "Colin Woodbury" Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] lisp/files.el: Add `file-name-set-extension` Date: Tue, 25 May 2021 14:44:30 -0700 Message-ID: <6ba4668c-9b39-40e0-a155-f7e583fd33b6@www.fastmail.com> References: <6ff4b7d7-03ac-48d1-8d49-de66431d4e5b@www.fastmail.com> <87lf82y9pv.fsf@tcd.ie> <3780a7f9-19f4-4216-baa9-ce00b3dbace9@www.fastmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=95076ad79a93486eb45262ee186413c3 Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36729"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Cyrus-JMAP/3.5.0-alpha0-448-gae190416c7-fm-20210505.004-gae190416 Cc: "Basil L. Contovounesios" , emacs-devel@gnu.org To: "Stefan Monnier" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue May 25 23:46:00 2021 Return-path: Envelope-to: ged-emacs-devel@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 1llesB-0009J4-VS for ged-emacs-devel@m.gmane-mx.org; Tue, 25 May 2021 23:46:00 +0200 Original-Received: from localhost ([::1]:58908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1llesA-0007n0-NZ for ged-emacs-devel@m.gmane-mx.org; Tue, 25 May 2021 17:45:58 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38996) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llerA-0006kE-VN for emacs-devel@gnu.org; Tue, 25 May 2021 17:44:57 -0400 Original-Received: from out4-smtp.messagingengine.com ([66.111.4.28]:36001) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ller8-0001m8-Kk for emacs-devel@gnu.org; Tue, 25 May 2021 17:44:56 -0400 Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 088865C022F; Tue, 25 May 2021 17:44:54 -0400 (EDT) Original-Received: from imap1 ([10.202.2.51]) by compute1.internal (MEProxy); Tue, 25 May 2021 17:44:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fosskers.ca; h= mime-version:message-id:in-reply-to:references:date:from:to:cc :subject:content-type; s=fm1; bh=mqKAS4CgcnGjOsxHPN1MIqWdeMECfDU Fe2itE9HortQ=; b=WHaRcV8PLAs+zF4Pewk9bNy8BiXp1YeDddCUIiVmh4Jt0oQ omWr3onrTYaOdmNF2B0Bx6qnZTkYF5A2kNFYzFDaFIhccRv2G0tfm2FxKPDKo0wN MZ/r+1cQUjllLNESBCDnGa2pkwzQy2BGFjcv8usbCz4Dt1+RqY0Rkh/iesbzPJad qoiggkKHlkTX/yzwyy09egoVo2HxY6CSVTB848QP1pi02tFdcc1pPzyji5oVha2H y2Zq7TKbQ7Wsoqdp1BIgHFx/IjoOBSXlz8fH65p7his1UHmbLfsELN5zOLqAABNS zhung9EZ/FpYq2rVMaS8rDeFHpF/QQ7Bzy17hIg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=mqKAS4 CgcnGjOsxHPN1MIqWdeMECfDUFe2itE9HortQ=; b=PnNUf0iI88FL6wLvLmiVnP biwYpYaQ7Ok1U3eWeUJgqwPLpMCbaEWcAfMgcPW3O19j2gCX6RVMXKbaTpRCMfBn j0SLx1uAXgbQSPRVEONiWSVaHaqGjsdo9VWUeZ7z0TQTs/GyhJfeHhMSBn8vO232 wxYbZB8W7v95vEikrouPsgVwkiRVKzaJhLdTxYyxMSA9jeisy5aQOZQXbbDgXMje lV46DQ0z8b4Tm6cw/fA8visqrK9boTyYgiMga723HTwzrQeZDJqzS313xQfeTSAO KMm78S0hI+Nq2NiftXyeH5i2obRHXZ9/I30aQ+q1OxTEfFV994A7lJZ1/1qv/pnQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvdekvddgtdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesmhdtreerreertdenucfhrhhomhepfdevohhl ihhnucghohhouggsuhhrhidfuceotgholhhinhesfhhoshhskhgvrhhsrdgtrgeqnecugg ftrfgrthhtvghrnhepffffgfehgeefgeevvddtgeeuuefhudefteegtdehkeegvdeifeev vdefgeeileejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homheptgholhhinhesfhhoshhskhgvrhhsrdgtrg X-ME-Proxy: Original-Received: by mailuser.nyi.internal (Postfix, from userid 501) id 85D93130005F; Tue, 25 May 2021 17:44:53 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface In-Reply-To: Received-SPF: none client-ip=66.111.4.28; envelope-from=colin@fosskers.ca; helo=out4-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, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:269901 Archived-At: --95076ad79a93486eb45262ee186413c3 Content-Type: multipart/alternative; boundary=00c8a2bfc1e647419b53a00da608d7c7 --00c8a2bfc1e647419b53a00da608d7c7 Content-Type: text/plain Thanks Stefan, I've revised the patch according to your suggestions (see attached). I also revised the docstring. Thanks! Colin On Tue, 25 May 2021, at 14:29, Stefan Monnier wrote: > > That regex was borrowed directly from `string-trim`, to which I added > > a `.`. You're right that the main motivation was to allow the caller to pass > > either `.foo` or `foo` as the extension and have either case work (many > > languages do this). Leaving the other characters in the regex seemed like > > a sanitary thing to do, just in case they pass something bogus. > > File names can be used in different ways for different purposes. > We don't have any good reason to think that a space or a newline at the > end of a file name (or beginning of an extension) is "bogus". > > If such things occurred somewhat often and always in ways where they are > indeed undesirable, we could consider removing them (the tradeoff > between occasional harm and frequent error-avoidance would be > favorable), but here this is just asking for trouble with no benefit. > > > 1. Simplifying the regex to just include dots (and perhaps whitespace) (i.e. trust the caller), or; > > Please do that. > > > 2. Expanding the logic to sanitize both ends of both arguments, (i.e. don't trust the caller), or; > > I don't think we have any reason to think we should "sanitize" it. > > > 3. Adding error-throwing logic if malformed files or extensions are given (i.e. warn the user). > > "Malformed" according to which standard? > > > Stefan > > --00c8a2bfc1e647419b53a00da608d7c7 Content-Type: text/html Content-Transfer-Encoding: quoted-printable
Thanks Stefan, = I've revised the patch according to your suggestions (see attached). I a= lso revised the docstring.

Thanks!
Colin

On Tue, 25 May 2021, at 14:29, = Stefan Monnier wrote:
> That regex was borrowed directly from `string-trim`, to = which I added
> a `.`. You're right that the main motiv= ation was to allow the caller to pass
> either `.foo` o= r `foo` as the extension and have either case work (many
&= gt; languages do this). Leaving the other characters in the regex seemed= like
> a sanitary thing to do, just in case they pass = something bogus.

File names can be used in = different ways for different purposes.
We don't have any g= ood reason to think that a space or a newline at the
end o= f a file name (or beginning of an extension) is "bogus".
<= br>
If such things occurred somewhat often and always in ways = where they are
indeed undesirable, we could consider remov= ing them (the tradeoff
between occasional harm and frequen= t error-avoidance would be
favorable), but here this is ju= st asking for trouble with no benefit.

>= 1. Simplifying the regex to just include dots (and perhaps whitespace) = (i.e. trust the caller), or;

Please do that= .

> 2. Expanding the logic to sanitize b= oth ends of both arguments, (i.e. don't trust the caller), or;
=

I don't think we have any reason to think we should = "sanitize" it.

> 3. Adding error-throwin= g logic if malformed files or extensions are given (i.e. warn the user).=

"Malformed" according to which standard?


     = ;   Stefan



--00c8a2bfc1e647419b53a00da608d7c7-- --95076ad79a93486eb45262ee186413c3 Content-Disposition: attachment;filename="file-name-set-extension.patch" Content-Type: text/x-patch; name="file-name-set-extension.patch" Content-Transfer-Encoding: BASE64 ZGlmZiAtLWdpdCBhL2xpc3AvZmlsZXMuZWwgYi9saXNwL2ZpbGVzLmVsCmluZGV4IDYyZTE3 MDJmZGYuLmFiOGJlNmFkOWUgMTAwNjQ0Ci0tLSBhL2xpc3AvZmlsZXMuZWwKKysrIGIvbGlz cC9maWxlcy5lbApAQCAtNDg4OSw2ICs0ODg5LDIxIEBAIGV4dGVuc2lvbiwgdGhlIHZhbHVl IGlzIFwiXCIuIgogICAgICAgICAoaWYgcGVyaW9kCiAgICAgICAgICAgICAiIikpKSkpCiAK KyhkZWZ1biBmaWxlLW5hbWUtc2V0LWV4dGVuc2lvbiAoZmlsZW5hbWUgZXh0ZW5zaW9uKQor ICAiU2V0IHRoZSBleHRlbnNpb24gb2YgYSBGSUxFTkFNRSB0byBFWFRFTlNJT04uCitDb25z b2xpZGF0ZXMgbGVhZGluZy90cmFpbGluZyBkb3RzIHN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