comparison mercurial/match.py @ 40775:4e02f25f31c6

match: test for overflow error in pattern If a single pattern is too large to handle, we raise an exception. This case is now doctested.
author Boris Feld <boris.feld@octobus.net>
date Thu, 22 Nov 2018 17:16:05 +0100
parents 8306dac48061
children ce401300f981
comparison
equal deleted inserted replaced
40774:8306dac48061 40775:4e02f25f31c6
1186 1186
1187 MAX_RE_SIZE = 20000 1187 MAX_RE_SIZE = 20000
1188 1188
1189 def _buildregexmatch(kindpats, globsuffix): 1189 def _buildregexmatch(kindpats, globsuffix):
1190 """Build a match function from a list of kinds and kindpats, 1190 """Build a match function from a list of kinds and kindpats,
1191 return regexp string and a matcher function.""" 1191 return regexp string and a matcher function.
1192
1193 Test too large input
1194 >>> _buildregexmatch([
1195 ... ('relglob', '?' * MAX_RE_SIZE, '')
1196 ... ], '$')
1197 Traceback (most recent call last):
1198 ...
1199 OverflowError
1200 """
1192 try: 1201 try:
1193 regex = '(?:%s)' % '|'.join([_regex(k, p, globsuffix) 1202 regex = '(?:%s)' % '|'.join([_regex(k, p, globsuffix)
1194 for (k, p, s) in kindpats]) 1203 for (k, p, s) in kindpats])
1195 if len(regex) <= MAX_RE_SIZE: 1204 if len(regex) <= MAX_RE_SIZE:
1196 return regex, _rematcher(regex) 1205 return regex, _rematcher(regex)