diff --git a/lib/controller/checks.py b/lib/controller/checks.py index c1549d0ec..79a262b5a 100644 --- a/lib/controller/checks.py +++ b/lib/controller/checks.py @@ -21,6 +21,7 @@ from lib.core.common import randomInt from lib.core.common import randomStr from lib.core.common import readInput from lib.core.common import showStaticWords +from lib.core.common import trimAlphaNum from lib.core.common import wasLastRequestDBMSError from lib.core.common import DynamicContentItem from lib.core.data import conf @@ -435,11 +436,8 @@ def checkDynamicContent(firstPage, secondPage): if suffix is None and (blocks[i][0] + blocks[i][2] >= len(firstPage)): continue - while prefix and prefix[-1].isalnum(): - prefix = prefix[:-1] - - while suffix and suffix[0].isalnum(): - suffix = suffix[1:] + prefix = trimAlphaNum(prefix) + suffix = trimAlphaNum(suffix) kb.dynamicMarkings.append((re.escape(prefix[-conf.dynMarkLength:]) if prefix else None, re.escape(suffix[:conf.dynMarkLength]) if suffix else None)) diff --git a/lib/core/common.py b/lib/core/common.py index 567c28c14..949fda69c 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -1627,3 +1627,15 @@ def extractRegexResult(regex, content, flags=0): retVal = match.group("result") return retVal + +def trimAlphaNum(value): + """ + Trims alpha numeric characters from start and ending of a given value + """ + while value and value[-1].isalnum(): + value = value[:-1] + + while value and value[0].isalnum(): + value = value[1:] + + return value