mirror of
https://github.com/python/cpython.git
synced 2025-08-25 11:15:02 +00:00
Issue #28350: String constants with null character no longer interned.
This commit is contained in:
parent
b47c9d29d7
commit
09f3d080fe
3 changed files with 27 additions and 11 deletions
|
@ -135,19 +135,27 @@ class CodeTest(unittest.TestCase):
|
|||
self.assertEqual(co.co_name, "funcname")
|
||||
self.assertEqual(co.co_firstlineno, 15)
|
||||
|
||||
|
||||
def isinterned(s):
|
||||
return s is sys.intern(('_' + s + '_')[1:-1])
|
||||
|
||||
class CodeConstsTest(unittest.TestCase):
|
||||
|
||||
def find_const(self, consts, value):
|
||||
for v in consts:
|
||||
if v == value:
|
||||
return v
|
||||
self.assertIn(value, consts) # rises an exception
|
||||
self.fail('Should be never reached')
|
||||
self.assertIn(value, consts) # raises an exception
|
||||
self.fail('Should never be reached')
|
||||
|
||||
def assertIsInterned(self, s):
|
||||
if s is not sys.intern(s):
|
||||
if not isinterned(s):
|
||||
self.fail('String %r is not interned' % (s,))
|
||||
|
||||
def assertIsNotInterned(self, s):
|
||||
if isinterned(s):
|
||||
self.fail('String %r is interned' % (s,))
|
||||
|
||||
@cpython_only
|
||||
def test_interned_string(self):
|
||||
co = compile('res = "str_value"', '?', 'exec')
|
||||
|
@ -172,6 +180,12 @@ class CodeConstsTest(unittest.TestCase):
|
|||
return a
|
||||
self.assertIsInterned(f())
|
||||
|
||||
@cpython_only
|
||||
def test_interned_string_with_null(self):
|
||||
co = compile(r'res = "str\0value!"', '?', 'exec')
|
||||
v = self.find_const(co.co_consts, 'str\0value!')
|
||||
self.assertIsNotInterned(v)
|
||||
|
||||
|
||||
class CodeWeakRefTest(unittest.TestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue