Skip to content

Commit

Permalink
Improve python p.a.c.k.er detection, fix #479
Browse files Browse the repository at this point in the history
  • Loading branch information
Einar Lielmanis committed Jun 16, 2014
1 parent 16ff816 commit 69be3c0
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions python/jsbeautifier/unpackers/packer.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,22 @@ def lookup(match):

def _filterargs(source):
"""Juice from a source file the four args needed by decoder."""
argsregex = (r"}\('(.*)', *(\d+), *(\d+), *'(.*)'\."
r"split\('\|'\), *(\d+), *(.*)\)\)")
args = re.search(argsregex, source, re.DOTALL).groups()
juicers = [ (r"}\('(.*)', *(\d+), *(\d+), *'(.*)'\.split\('\|'\), *(\d+), *(.*)\)\)"),
(r"}\('(.*)', *(\d+), *(\d+), *'(.*)'\.split\('\|'\)"),
]
for juicer in juicers:
args = re.search(juicer, source, re.DOTALL)
if args:
a = args.groups()
try:
return a[0], a[3].split('|'), int(a[1]), int(a[2])
except ValueError:
raise UnpackingError('Corrupted p.a.c.k.e.r. data.')

# could not find a satisfying regex
raise UnpackingError('Could not make sense of p.a.c.k.e.r data (unexpected code structure)')


try:
return args[0], args[3].split('|'), int(args[1]), int(args[2])
except ValueError:
raise UnpackingError('Corrupted p.a.c.k.e.r. data.')

def _replacestrings(source):
"""Strip string lookup table (list) and replace values in source."""
Expand Down

0 comments on commit 69be3c0

Please sign in to comment.