Merge pull request #71 from gutenbergtools/harden

Harden
master
Eric Hellman 2021-02-18 11:31:41 -05:00 committed by GitHub
commit c541960cf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 0 deletions

View File

@ -189,6 +189,8 @@ class SQLStatement(object):
@classmethod
def sub(cls, regex_, replace, query):
""" Like re.sub but also compile and cache the regex. """
if not isinstance(query, str):
query = query[0] if isinstance(query, list) and len(query) > 0 else ''
cregex = cls.regex_cache.setdefault(
regex_, regex.compile(regex_, regex.UNICODE | regex.VERSION1))