mirror of
https://github.com/l1ving/youtube-dl
synced 2020-11-18 19:53:54 -08:00
Merge branch 'utils' into sulyi
This commit is contained in:
commit
7c57ded9b0
@ -743,6 +743,26 @@ class TestUtil(unittest.TestCase):
|
|||||||
inp = '''{"duration": "00:01:07"}'''
|
inp = '''{"duration": "00:01:07"}'''
|
||||||
self.assertEqual(js_to_json(inp), '''{"duration": "00:01:07"}''')
|
self.assertEqual(js_to_json(inp), '''{"duration": "00:01:07"}''')
|
||||||
|
|
||||||
|
def test_js_to_json_landofoz(self):
|
||||||
|
inp = '''{
|
||||||
|
character: {
|
||||||
|
name: "Dorothy",
|
||||||
|
pet: "Toto",
|
||||||
|
/* source: "Kansas",
|
||||||
|
destination: "Emerald City",
|
||||||
|
roll: "heroine" */
|
||||||
|
},
|
||||||
|
comment: /* over the rainbow */ "/*",
|
||||||
|
no_comment: "*/"
|
||||||
|
}'''
|
||||||
|
self.assertEqual(js_to_json(inp), '''{
|
||||||
|
"character": {
|
||||||
|
"name": "Dorothy",
|
||||||
|
"pet": "Toto"\n \n },
|
||||||
|
"comment": "/*",
|
||||||
|
"no_comment": "*/"
|
||||||
|
}''')
|
||||||
|
|
||||||
def test_js_to_json_edgecases(self):
|
def test_js_to_json_edgecases(self):
|
||||||
on = js_to_json("{abc_def:'1\\'\\\\2\\\\\\'3\"4'}")
|
on = js_to_json("{abc_def:'1\\'\\\\2\\\\\\'3\"4'}")
|
||||||
self.assertEqual(json.loads(on), {"abc_def": "1'\\2\\'3\"4"})
|
self.assertEqual(json.loads(on), {"abc_def": "1'\\2\\'3\"4"})
|
||||||
|
@ -2109,14 +2109,11 @@ def js_to_json(code):
|
|||||||
|
|
||||||
return '"%s"' % v
|
return '"%s"' % v
|
||||||
|
|
||||||
# fixing , followed nothing, but comments
|
|
||||||
# fixing unnecessary ? in /\*.*?\*/
|
|
||||||
# fixing greedy comment
|
|
||||||
return re.sub(r'''(?sx)
|
return re.sub(r'''(?sx)
|
||||||
"(?:[^"\\]*(?:\\\\|\\['"nurtbfx/\n]))*[^"\\]*"|
|
"(?:[^"\\]*(?:\\\\|\\['"nurtbfx/\n]))*[^"\\]*"|
|
||||||
'(?:[^'\\]*(?:\\\\|\\['"nurtbfx/\n]))*[^'\\]*'|
|
'(?:[^'\\]*(?:\\\\|\\['"nurtbfx/\n]))*[^'\\]*'|
|
||||||
,(?=(\s|(/\*((?!\*/)\n|.)*\*/))*[\]}])|
|
,(?=(?:\s|(?:/\*(?:(?!\*/)(?:\n|.))*\*/))*[\]}])|
|
||||||
/\*((?!\*/)\n|.)*\*/|[a-zA-Z_][.a-zA-Z_0-9]*|
|
/\*(?:(?!\*/)(?:\n|.))*\*/|[a-zA-Z_][.a-zA-Z_0-9]*|
|
||||||
\b(?:0[xX][0-9a-fA-F]+|0+[0-7]+)(?:\s*:)?|
|
\b(?:0[xX][0-9a-fA-F]+|0+[0-7]+)(?:\s*:)?|
|
||||||
[0-9]+(?=\s*:)
|
[0-9]+(?=\s*:)
|
||||||
''', fix_kv, code)
|
''', fix_kv, code)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user