Skip to content

Commit

Permalink
Fix quadratic complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
yurikhan authored Dec 14, 2021
1 parent 03f3f27 commit 631e8b7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions json_minify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

def json_minify(string, strip_space=True):
tokenizer = re.compile('"|(/\*)|(\*/)|(//)|\n|\r')
end_slashes_re = re.compile(r'(\\)*$')

in_string = False
in_multi = False
Expand All @@ -44,10 +43,12 @@ def json_minify(string, strip_space=True):
val = match.group()

if val == '"' and not (in_multi or in_single):
escaped = end_slashes_re.search(string, 0, match.start())
pos = match.start()
while pos > 0 and string[pos - 1] == '\\':
pos -= 1

# start of string or unescaped quote character to end string
if not in_string or (escaped is None or len(escaped.group()) % 2 == 0): # noqa
if not in_string or (match.start() - pos) % 2 == 0: # noqa
in_string = not in_string
index -= 1 # include " character in next catch
elif not (in_string or in_multi or in_single):
Expand Down

0 comments on commit 631e8b7

Please sign in to comment.