emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] lisp/files.el: Add `file-name-set-extension`


From: Stefan Monnier
Subject: Re: [PATCH] lisp/files.el: Add `file-name-set-extension`
Date: Tue, 25 May 2021 17:29:19 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]