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