Skip to content

Commit e912e94

Browse files
bpo-41944: No longer call eval() on content received via HTTP in the CJK codec tests (GH-22566) (GH-22579)
(cherry picked from commit 2ef5caa) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent a158fb9 commit e912e94

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

Lib/test/multibytecodec_support.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -300,29 +300,23 @@ def test_mapping_file(self):
300300
self._test_mapping_file_plain()
301301

302302
def _test_mapping_file_plain(self):
303-
unichrs = lambda s: ''.join(map(chr, map(eval, s.split('+'))))
303+
def unichrs(s):
304+
return ''.join(chr(int(x, 16)) for x in s.split('+'))
305+
304306
urt_wa = {}
305307

306308
with self.open_mapping_file() as f:
307309
for line in f:
308310
if not line:
309311
break
310-
data = line.split('#')[0].strip().split()
312+
data = line.split('#')[0].split()
311313
if len(data) != 2:
312314
continue
313315

314-
csetval = eval(data[0])
315-
if csetval <= 0x7F:
316-
csetch = bytes([csetval & 0xff])
317-
elif csetval >= 0x1000000:
318-
csetch = bytes([(csetval >> 24), ((csetval >> 16) & 0xff),
319-
((csetval >> 8) & 0xff), (csetval & 0xff)])
320-
elif csetval >= 0x10000:
321-
csetch = bytes([(csetval >> 16), ((csetval >> 8) & 0xff),
322-
(csetval & 0xff)])
323-
elif csetval >= 0x100:
324-
csetch = bytes([(csetval >> 8), (csetval & 0xff)])
325-
else:
316+
if data[0][:2] != '0x':
317+
self.fail(f"Invalid line: {line!r}")
318+
csetch = bytes.fromhex(data[0][2:])
319+
if len(csetch) == 1 and 0x80 <= csetch[0]:
326320
continue
327321

328322
unich = unichrs(data[1])
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Tests for CJK codecs no longer call ``eval()`` on content received via HTTP.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy