mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-07 20:30:41 -05:00
Fix unicode_escape (Fixes #2695)
This commit is contained in:
parent
98b7cf1ace
commit
676eb3f2dd
2 changed files with 8 additions and 1 deletions
|
@ -38,6 +38,7 @@
|
||||||
xpath_with_ns,
|
xpath_with_ns,
|
||||||
parse_iso8601,
|
parse_iso8601,
|
||||||
strip_jsonp,
|
strip_jsonp,
|
||||||
|
uppercase_escape,
|
||||||
)
|
)
|
||||||
|
|
||||||
if sys.version_info < (3, 0):
|
if sys.version_info < (3, 0):
|
||||||
|
@ -279,6 +280,9 @@ def test_strip_jsonp(self):
|
||||||
d = json.loads(stripped)
|
d = json.loads(stripped)
|
||||||
self.assertEqual(d, [{"id": "532cb", "x": 3}])
|
self.assertEqual(d, [{"id": "532cb", "x": 3}])
|
||||||
|
|
||||||
|
def test_uppercase_escpae(self):
|
||||||
|
self.assertEqual(uppercase_escape(u'aä'), u'aä')
|
||||||
|
self.assertEqual(uppercase_escape(u'\\U0001d550'), u'𝕐')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import calendar
|
import calendar
|
||||||
|
import codecs
|
||||||
import contextlib
|
import contextlib
|
||||||
import ctypes
|
import ctypes
|
||||||
import datetime
|
import datetime
|
||||||
|
@ -1263,9 +1264,11 @@ def getslice(self, start=0, end=None):
|
||||||
|
|
||||||
|
|
||||||
def uppercase_escape(s):
|
def uppercase_escape(s):
|
||||||
|
unicode_escape = codecs.getdecoder('unicode_escape')
|
||||||
return re.sub(
|
return re.sub(
|
||||||
r'\\U[0-9a-fA-F]{8}',
|
r'\\U[0-9a-fA-F]{8}',
|
||||||
lambda m: m.group(0).decode('unicode-escape'), s)
|
lambda m: unicode_escape(m.group(0))[0],
|
||||||
|
s)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
struct.pack(u'!I', 0)
|
struct.pack(u'!I', 0)
|
||||||
|
|
Loading…
Reference in a new issue