<div dir="ltr"><div>Call me old, but this is 35+ years of experience talking. </div>My advice to you is: rename your files to eliminate the special chars.<div>Even if you get this working, every person that installs your .rpm will curse you</div><div>b/c now they have to figure out how to special case your special filenames too,</div><div>Don't put spaces/(special chars) in filenames.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jun 29, 2021 at 5:32 AM Miro Hrončok <<a href="mailto:mhroncok@redhat.com">mhroncok@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello,<br>
<br>
we have a filelist generator and recently I've discovered a bug when the path <br>
contains a space. Our generator generates one path fer line in a text file that <br>
is to be used via %file -f.<br>
<br>
<br>
Suppose the path is:<br>
<br>
/usr/share/data/filename with spaces in it<br>
<br>
In that case, when we literally include this line in the filelist, RPM says <br>
that "with", "spaces", "in" and "it" does not start with "/".<br>
<br>
Quite easily I was able to find out that we need to write the path like this:<br>
<br>
"/usr/share/data/filename with spaces in it"<br>
<br>
That works, so I was about to write a function (in Python) that puts the entire <br>
path in "double quotes" if it contains some space characters (spaces, new <br>
lines, etc.).<br>
<br>
However, I have trouble figuring out how to properly escape a path like this:<br>
<br>
/usr/share/data/filename with spaces and "quotes" in it<br>
<br>
I've tried the following options with no luck:<br>
<br>
'/usr/share/data/filename with spaces and "quotes" in it'<br>
"/usr/share/data/filename with spaces and \"quotes\" in it"<br>
"/usr/share/data/filename with spaces and \\"quotes\\" in it"<br>
"/usr/share/data/filename with spaces and \\\"quotes\\\" in it"<br>
<br>
While at it, I've also tried to figure out how to escape a % symbol in path. <br>
Suppose the path is literally:<br>
<br>
/usr/share/data/%version<br>
<br>
I've tried the following options with no luck:<br>
<br>
"/usr/share/data/%version"<br>
/usr/share/data/%%version<br>
/usr/share/data/%%%version<br>
/usr/share/data/%%%%version<br>
/usr/share/data/%%%%%version ...<br>
<br>
<br>
<br>
This is my function so far, but it is quite incomplete:<br>
<br>
import string<br>
<br>
def escape_rpm_path(path):<br>
     """<br>
     Escape special characters in paths<br>
     E.g. a space in path otherwise makes RPM think it's multiple paths,<br>
     unless we put it in "quotes".<br>
     Or a literal % symbol in path might be expanded as a macro if not escaped.<br>
     """<br>
     if "%" in path:<br>
         # path = path.replace("%", "%%") is not enough<br>
         raise NotImplementedError("% symbol in paths, dunno")<br>
<br>
     if any(symbol in path for symbol in string.whitespace):<br>
         if '"' in path:<br>
             raise NotImplementedError('" symbol in path with spaces, dunno')<br>
         return f'"{path}"'<br>
<br>
     # I wish all paths in the world would end up here:<br>
     return path<br>
<br>
<br>
What do I do? Is there a specification for the filelist syntax somewhere?<br>
<br>
<br>
Thanks,<br>
-- <br>
Miro Hrončok<br>
-- <br>
Phone: +420777974800<br>
IRC: mhroncok<br>
<br>
_______________________________________________<br>
Rpm-list mailing list<br>
<a href="mailto:Rpm-list@lists.rpm.org" target="_blank">Rpm-list@lists.rpm.org</a><br>
<a href="http://lists.rpm.org/mailman/listinfo/rpm-list" rel="noreferrer" target="_blank">http://lists.rpm.org/mailman/listinfo/rpm-list</a><br>
</blockquote></div>