comparison mercurial/sslutil.py @ 38475:67dc32d4e790

cleanup: migrate from re.escape to stringutil.reescape This has consistent behavior on Python 2.7, 3.6, and 3.7 and has the benefit of probably being a little faster. Test output changes are largely because / used to be pointlessly escaped. Differential Revision: https://phab.mercurial-scm.org/D3842
author Augie Fackler <augie@google.com>
date Tue, 26 Jun 2018 10:36:23 -0400
parents 51a2f8d199c7
children 0d226b2139df
comparison
equal deleted inserted replaced
38474:96f65bdf0bf4 38475:67dc32d4e790
616 elif leftmost.startswith('xn--') or hostname.startswith('xn--'): 616 elif leftmost.startswith('xn--') or hostname.startswith('xn--'):
617 # RFC 6125, section 6.4.3, subitem 3. 617 # RFC 6125, section 6.4.3, subitem 3.
618 # The client SHOULD NOT attempt to match a presented identifier 618 # The client SHOULD NOT attempt to match a presented identifier
619 # where the wildcard character is embedded within an A-label or 619 # where the wildcard character is embedded within an A-label or
620 # U-label of an internationalized domain name. 620 # U-label of an internationalized domain name.
621 pats.append(re.escape(leftmost)) 621 pats.append(stringutil.reescape(leftmost))
622 else: 622 else:
623 # Otherwise, '*' matches any dotless string, e.g. www* 623 # Otherwise, '*' matches any dotless string, e.g. www*
624 pats.append(re.escape(leftmost).replace(br'\*', '[^.]*')) 624 pats.append(stringutil.reescape(leftmost).replace(br'\*', '[^.]*'))
625 625
626 # add the remaining fragments, ignore any wildcards 626 # add the remaining fragments, ignore any wildcards
627 for frag in remainder: 627 for frag in remainder:
628 pats.append(re.escape(frag)) 628 pats.append(stringutil.reescape(frag))
629 629
630 pat = re.compile(br'\A' + br'\.'.join(pats) + br'\Z', re.IGNORECASE) 630 pat = re.compile(br'\A' + br'\.'.join(pats) + br'\Z', re.IGNORECASE)
631 return pat.match(hostname) is not None 631 return pat.match(hostname) is not None
632 632
633 def _verifycert(cert, hostname): 633 def _verifycert(cert, hostname):