← Back to team overview

curtin-dev team mailing list archive

Re: [Merge] ~raharper/curtin:fix/udevadm-info-shlex-quote into curtin:master

 

On Tue, Apr 28, 2020 at 04:53:30PM -0000, Ryan Harper wrote:
> > +try:
> > +    shlex_quote = shlex.quote
> > +except AttributeError:
> > +    # python2.7 shlex does not have quote, give it a try
> > +    def shlex_quote(value):
> 
> Yes, that seems *much* better.  Thanks for tracking it down.

No problem!

> > +                    # strip the leading/ending single tick from udev output
> 
> I'll rework.

Thanks!

> > +        self.assertEqual('SanDisk'"'"'', info['SCSI_VENDOR'])
> 
> What's wrong with matching the exact output from shlex_quote() ?
> 
> % python3
> Python 3.8.2 (default, Mar 13 2020, 10:14:16) 
> [GCC 9.3.0] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import shlex
> >>> shlex.quote("SanDisk'")
> '\'SanDisk\'"\'"\'\''
> >>> print(shlex.quote("SanDisk'"))
> 'SanDisk'"'"''
> >>>

I don't think that's what you're doing:

    In [4]: 'SanDisk'"'"'' == shlex.quote("SanDisk'")
    Out[4]: False

'SanDisk'"'"'' is equivalent to `'SanDisk' + "'" + ''`, which:

    In [5]: 'SanDisk'"'"'' == "SanDisk'"
    Out[5]: True

effectively undoes the escaping.  This is a little easier to see in
triple quotes (where all the double and single quotes do not need
escaping, and I added newlines and a .strip() for further clarity):

    In [13]: """
        ...: 'SanDisk'"'"''
        ...: """.strip() == shlex.quote("SanDisk'")
    Out[13]: True

-- 
https://code.launchpad.net/~raharper/curtin/+git/curtin/+merge/382993
Your team curtin developers is subscribed to branch curtin:master.


References