aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2016-05-14 20:39:58 +0600
committerSergey M․ <dstftw@gmail.com>2016-05-14 20:39:58 +0600
commit89ac4a19e658203db85c6a1d4b267a2eeb47a38e (patch)
treed076cf3a60b4960e63d0b5803a8d2151509b5498 /youtube_dl
parent640eea0a0cf7ae589126f7762e1cfc7bdd2250d9 (diff)
[utils] Process non-base 10 integers in js_to_json
Diffstat (limited to 'youtube_dl')
-rw-r--r--youtube_dl/utils.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index 52a20632f..25a9f33c0 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -1925,6 +1925,17 @@ def js_to_json(code):
'\\x': '\\u00',
}.get(m.group(0), m.group(0)), v[1:-1])
+ INTEGER_TABLE = (
+ (r'^(0[xX][0-9a-fA-F]+)', 16),
+ (r'^(0+[0-7]+)', 8),
+ )
+
+ for regex, base in INTEGER_TABLE:
+ im = re.match(regex, v)
+ if im:
+ i = int(im.group(1), base)
+ return '"%d":' % i if v.endswith(':') else '%d' % i
+
return '"%s"' % v
return re.sub(r'''(?sx)
@@ -1932,6 +1943,7 @@ def js_to_json(code):
'(?:[^'\\]*(?:\\\\|\\['"nurtbfx/\n]))*[^'\\]*'|
/\*.*?\*/|,(?=\s*[\]}])|
[a-zA-Z_][.a-zA-Z_0-9]*|
+ (?:0[xX][0-9a-fA-F]+|0+[0-7]+)(?:\s*:)?|
[0-9]+(?=\s*:)
''', fix_kv, code)