changeset 225:fba806958dba

tests: add regression test to check for null byte handling
author Mathias De Mare <mathias.de_mare@nokia.com>
date Tue, 14 Mar 2023 14:35:58 +0100
parents 2ab42323f149
children 7b6ea46ea111
files tests/test_heads.py tests/test_log.py
diffstat 2 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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'))
--- 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')