[Twisted-Python] Re: [Twisted-commits] r15000 - Potential fix for issue1123.

James Y Knight foom at fuhm.net
Wed Nov 2 17:56:32 EST 2005


On Nov 2, 2005, at 3:50 PM, Justin Johnson wrote:
>  _cmdLineQuoteRe = re.compile(r'(\\*)"')
>  def _cmdLineQuote(s):
> -    return '"' + _cmdLineQuoteRe.sub(r'\1\1\\"', s) + '"'
> +    quote = ((" " in s) or ("\t" in s)) and '"' or ''
> +    return quote + _cmdLineQuoteRe.sub(r'\1\1\\"', s) + quote


That should be checking for a doublequote in addition to space and tab.

Also I just noticed another bug:
With input string (two characters):
"\
the output should be (6 chars):
"\"\\"
but is currently completely incorrect:
"\"\"

I think that second can be fixed with:
_cmdLineQuoteRe = re.compile(r'(\\*)"')
_cmdLineQuoteRe2 = re.compile(r'(\\+)\Z')
def _cmdLineQuote(s):
     return '"' + _cmdLineQuoteRe2.sub(r"\1\1", _cmdLineQuoteRe.sub 
(r'\1\1\\"', s)) + '"'

James




More information about the Twisted-Python mailing list