[PATCH rfc] check-code: detect r'...\'...'

Mads Kiilerich mads at kiilerich.com
Wed Nov 9 10:45:02 CST 2011


On 11/09/2011 03:31 PM, Matt Mackall wrote:
> On Wed, 2011-11-09 at 02:37 +0100, Mads Kiilerich wrote:
>> # HG changeset patch
>> # User Mads Kiilerich<mads at kiilerich.com>
>> # Date 1320802647 -3600
>> # Node ID 20fe74e6bcd0518b108f85270c880f330963c490
>> # Parent  de7e2fba4326cad80bda0cb100d2ae2f58e67ee8
>> check-code: detect r'...\'...'
>
> Not sure why this matters:
>
>>>> a = r'x\'x'
>>>> b = 'x\'x'
>>>> a == b
> False
>>>> b.replace(a, 'foo') # shouldn't work
> "x'x"
>>>> import re
>>>> re.sub(a, 'foo', b) # should work
> 'foo'
>
> Despite the fact that r'x\'x' is really "x\\'x", the regex engine turns
> "\\'" back into a "'" and the expression functions as expected.

You are right. Assuming the raw strings are used as regexp then it for 
all(?) practical purposes doesn't matter that there are extra \'s in the 
string. It just looks confusing and sloppy, IMHO.

r'\'' == r"\'" == '\\\'' == "\\'"

as regexp pattern always(?) works exactly(?) like

"'"

/Mads


More information about the Mercurial-devel mailing list