[PATCH 2 of 5 V4] match: test for overflow error in pattern

Boris Feld boris.feld at octobus.net
Sat Dec 1 07:07:32 EST 2018


# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1542903365 -3600
#      Thu Nov 22 17:16:05 2018 +0100
# Node ID 062da9819592bc5abd87b9a2e00739bb6729015d
# Parent  cd8a3de2d43af89b3db66f6c539a11ef80feb5a2
# EXP-Topic perf-ignore
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 062da9819592
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.

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -1188,7 +1188,16 @@ MAX_RE_SIZE = 20000
 
 def _buildregexmatch(kindpats, globsuffix):
     """Build a match function from a list of kinds and kindpats,
-    return regexp string and a matcher function."""
+    return regexp string and a matcher function.
+
+    Test too large input
+    >>> _buildregexmatch([
+    ...     ('relglob', '?' * MAX_RE_SIZE, '')
+    ... ], '$')
+    Traceback (most recent call last):
+    ...
+    OverflowError
+    """
     try:
         regex = '(?:%s)' % '|'.join([_regex(k, p, globsuffix)
                                      for (k, p, s) in kindpats])


More information about the Mercurial-devel mailing list