Jason R. Coombs  committed 7dede23

Adding two tests demonstrating improper escaping of low bytes

  • Participants
  • Parent commits 6ad9585

Comments (0)

Files changed (1)

File keyring/tests/

 import unittest
-import os
-import sys
-import tempfile
-import shutil
 from keyring.util import escape
         self.check_escape_unescape(u"Zażółć gęślą jaźń")
         self.check_escape_unescape("(((P{{{{'''---; ;; '\"|%^")
+    def test_low_byte(self):
+        """
+        The current encoding allows low bytes (less than hex 16) to encode
+        as two bytes. For example '\n' (hex A) will encode as '_A', which
+        isn't matched by the inverse operation.
+        """
+        self.check_escape_unescape('\n')
+    def test_ambiguous_string(self):
+        """
+        The current encoding encodes each non-alphanumeric byte to _XX where
+        XX is the hex code for that byte. However, it doesn't encode dual-
+        digits, so '\x00' encodes to '_0'. Thus, if one tries to escape the
+        string '\x000' (the null byte followed by the number 0), it will be
+        encoded to '_00', which decodes to '\x00'.
+        """
+        self.check_escape_unescape('\x000')
 def test_suite():
     suite = unittest.TestSuite()