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

login
register
mail settings
Submitter Boris Feld
Date Nov. 22, 2018, 10:17 p.m.
Message ID <b702174979d09090d5e5.1542925040@localhost.localdomain>
Download mbox | patch
Permalink /patch/36726/
State Superseded
Headers show

Comments

Boris Feld - Nov. 22, 2018, 10:17 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 b702174979d09090d5e5081d09755cbb74540ff0
# Parent  7540e746d44775c7098d5fa473be9968317616f1
# EXP-Topic perf-ignore-2
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r b702174979d0
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 @@  MAXRESIZE = 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', '?' * MAXRESIZE, '')
+    ... ], '$')
+    Traceback (most recent call last):
+    ...
+    OverflowError
+    """
     try:
         regex = '(?:%s)' % '|'.join([_regex(k, p, globsuffix)
                                      for (k, p, s) in kindpats])