# HG changeset patch # User Mathias De Mare # Date 1678800958 -3600 # Node ID fba806958dba493dc0761439aacc00f39e813672 # Parent 2ab42323f1499669fe8b110b0d28b93bcd3044e4 tests: add regression test to check for null byte handling diff -r 2ab42323f149 -r fba806958dba tests/test_heads.py --- a/tests/test_heads.py Mon Mar 13 15:32:20 2023 +0100 +++ b/tests/test_heads.py Tue Mar 14 14:35:58 2023 +0100 @@ -1,5 +1,6 @@ from tests import common from hglib.util import b +import subprocess class test_heads(common.basetest): def test_empty(self): @@ -15,3 +16,14 @@ rev, node1 = self.client.commit(b('second')) self.assertEqual(self.client.heads(node0, topological=True), []) + + def test_null_byte(self): + self.append('a', 'a') + with open('commitmessagenullbyte', 'w') as f: + f.write('some message\0more stuff') + # use 'hg' directly here as hglib doesn't allow + # committing null byte descriptions + subprocess.check_call(["hg", "commit", + "-l", "commitmessagenullbyte", "--addremove", "-q"]) + revs = self.client.heads() + self.assertEqual(revs[0].desc, b('some message\0more stuff')) diff -r 2ab42323f149 -r fba806958dba tests/test_log.py --- a/tests/test_log.py Mon Mar 13 15:32:20 2023 +0100 +++ b/tests/test_log.py Tue Mar 14 14:35:58 2023 +0100 @@ -1,6 +1,7 @@ from tests import common import hglib from hglib.util import b +import subprocess class test_log(common.basetest): def test_basic(self): @@ -34,6 +35,17 @@ self.assertTrue(len(revs) == 1) self.assertEqual(revs[0].rev, b('0')) + def test_null_byte(self): + self.append('a', 'a') + with open('commitmessagenullbyte', 'w') as f: + f.write('some message\0more stuff') + # use 'hg' directly here as hglib doesn't allow + # committing null byte descriptions + subprocess.check_call(["hg", "commit", + "-l", "commitmessagenullbyte", "--addremove", "-q"]) + revs = self.client.log(revrange=b('.')) + self.assertEqual(revs[0].desc, b('some message\0more stuff')) + # def test_errors(self): # self.assertRaisesRegexp(CommandError, 'abort: unknown revision', # self.client.log, 'foo')