From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] lisp/files.el: Add `file-name-set-extension` Date: Tue, 25 May 2021 17:29:19 -0400 Message-ID: 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: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5754"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: "Basil L. Contovounesios" , emacs-devel@gnu.org To: "Colin Woodbury" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue May 25 23:31:26 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 1llee5-0001Ii-P5 for ged-emacs-devel@m.gmane-mx.org; Tue, 25 May 2021 23:31:26 +0200 Original-Received: from localhost ([::1]:48928 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1llee4-000073-RU for ged-emacs-devel@m.gmane-mx.org; Tue, 25 May 2021 17:31:24 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35760) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llecH-0007kF-R7 for emacs-devel@gnu.org; Tue, 25 May 2021 17:29:33 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:55577) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llec8-0000xn-Hb for emacs-devel@gnu.org; Tue, 25 May 2021 17:29:33 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 16C2B10020E; Tue, 25 May 2021 17:29:23 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 12E77100068; Tue, 25 May 2021 17:29:21 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1621978161; bh=HU9r7c5dLth/GHgXxcuuUG/CK9hOllh7WXMhJxxZ4F4=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=HF4fybiHkdWceXWTdvWuqaHn12y7QfwxjKeXTSX+MaEgd7ZbasBt6kw1S5rLkt5Gg WeqJtSOoxn9UBljVMW5nN2JPA/YeQ9NHYNXUu8j7q3Yly0IgT4onCd7Hf7W4N2S779 YS2hPu+jd+sFkMljsT4YS8niKAmi+9essf8zEjFeB985h7Gbm83Si7P+6kB9r3H2/h TaZphz0nZv6ITXRZ26a//kIjJKvNX7+x7c5cmTUXXhh+3IVtxKxCChRtsHkP7sYvG8 D1kui8IOtGLT5Bq2fYawfU1bB6fpYoKPaTg2krlbHJ7xhCdHqXMBvlvAKp02/y61Tl 5ST766y7xDwyQ== Original-Received: from alfajor (69-196-163-239.dsl.teksavvy.com [69.196.163.239]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id CF61E12026E; Tue, 25 May 2021 17:29:20 -0400 (EDT) In-Reply-To: <3780a7f9-19f4-4216-baa9-ce00b3dbace9@www.fastmail.com> (Colin Woodbury's message of "Tue, 25 May 2021 14:21:07 -0700") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-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:269899 Archived-At: > 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