[Rpm-maint] [rpm-software-management/rpm] Shell-like escaping support in %files (PR #1903)
Michal Domonkos
notifications at github.com
Fri Mar 18 09:04:14 UTC 2022
@dmnks commented on this pull request.
> @@ -665,6 +665,20 @@ void rpmUnescape(char *s)
*p = '\0';
}
+void rpmUnescapeQuotes(char *s)
+{
+ char *p, *q;
+ int esc = 0;
+ p = q = s;
+ while (*q != '\0') {
+ *p = *q++;
+ esc = (*p == '\\') && !esc && *q == '"';
OK, let me explain the logic here:
The function `parseForSimple()` accepts quotes as a way to escape spaces (normally, multiple filenames are accepted on a single line in the `%files` section, each separated by whitespace). The tokenization into filenames is done in a loop by the `strtokWithQuotes()` function here, which is *where the quote semantics apply*. Once that's done, any quotes are supposed to have been consumed and so they no longer have any meaning and thus should be stripped; for the outermost quotes, this is already done by `strtokWithQuotes()` because it returns a quoted token without the opening and closing quotes. IOW, the *scope* of the quotes here is filename tokenization (the `strtokWithQuotes()` call). Any such quotes should be discarded in the resulting token (a filename) before we pass it further.
Now, backslashes used to denote literal quotes have the same scope as normal quotes; they are only meaningful for filename tokenization, not beyond that. So the same applies as above; discard such backslashes ("unescape") as soon as we're done tokenizing (we want just the quotes in the resulting filename(s), not the backslashes preceding them).
So we only want to unescape quotes here, not anything else, because we're already processing a single filename which is enclosed in quotes; that's the (non-obvious) `(s != t)` check. If there are other escaped chars in the filename, that's OK and we ignore them, because we do want those to be literal, as that's the semantics of quoted strings.
For example:
```
%files
"/foo\"bar"
"/foo\[bar"
```
These should be processed and eventually stat-ed as follows: `/foo"bar` and `/foo\[bar`.
I hope that makes sense :)
--
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/pull/1903#discussion_r829809392
You are receiving this because you are subscribed to this thread.
Message ID: <rpm-software-management/rpm/pull/1903/review/914098273 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20220318/d860b003/attachment-0001.html>
More information about the Rpm-maint
mailing list