Patchwork [3,of,6,V3] match: test for overflow error in pattern

login
register
mail settings
Submitter Boris Feld
Date Nov. 23, 2018, 2:12 p.m.
Message ID <1fccf5fa1c8a65654083.1542982366@localhost.localdomain>
Download mbox | patch
Permalink /patch/36745/
State Accepted
Headers show

Comments

Boris Feld - Nov. 23, 2018, 2:12 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1542903365 -3600
#      Thu Nov 22 17:16:05 2018 +0100
# Node ID 1fccf5fa1c8a65654083c85107649124f0721ffe
# Parent  8847fda442975010d004dcb0293a40ba70434070
# EXP-Topic perf-ignore
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 1fccf5fa1c8a
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.

Patch

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])