diff --git a/avocado/utils/astring.py b/avocado/utils/astring.py index dfa15a878ba9e02709cabd87a225c9924968e18e..eb18ad5276d6679708def91ca5d788db7361fe70 100644 --- a/avocado/utils/astring.py +++ b/avocado/utils/astring.py @@ -217,4 +217,6 @@ def string_to_safe_path(string): :param string: String to be converted :return: String which is safe to pass as a file/dir name (on recent fs) """ + if string.startswith("."): + string = "_" + string[1:] return string.replace(os.path.sep, '_')[:255] diff --git a/selftests/unit/test_test.py b/selftests/unit/test_test.py index 1a3123fbab9749cdfa407c4a3b438e4e338d907c..b11f847e07b47c02a6b688395e9dceff22880a62 100644 --- a/selftests/unit/test_test.py +++ b/selftests/unit/test_test.py @@ -34,6 +34,31 @@ class TestClassTestUnit(unittest.TestCase): def tearDown(self): shutil.rmtree(self.tmpdir) + def testUglyName(self): + def run(name, path_name): + """ Initialize test and check the dirs were created """ + test = DummyTest("test", name, base_logdir=self.tmpdir) + self.assertEqual(os.path.basename(test.logdir), path_name) + self.assertTrue(os.path.exists(test.logdir)) + self.assertEqual(os.path.dirname(os.path.dirname(test.logdir)), + self.tmpdir) + + run("/absolute/path", "_absolute_path") + run("./relative/path", "__relative_path") + run("../../multi_level/relative/path", + "_._.._multi_level_relative_path") + # Greek word 'kosme' + run("\xce\xba\xe1\xbd\xb9\xcf\x83\xce\xbc\xce\xb5", + "\xce\xba\xe1\xbd\xb9\xcf\x83\xce\xbc\xce\xb5") + # Particularly problematic noncharacters in 16-bit applications + name = ("\xb7\x95\xef\xb7\x96\xef\xb7\x97\xef\xb7\x98\xef\xb7\x99" + "\xef\xb7\x9a\xef\xb7\x9b\xef\xb7\x9c\xef\xb7\x9d\xef\xb7" + "\x9e\xef\xb7\x9f\xef\xb7\xa0\xef\xb7\xa1\xef\xb7\xa2\xef" + "\xb7\xa3\xef\xb7\xa4\xef\xb7\xa5\xef\xb7\xa6\xef\xb7\xa7" + "\xef\xb7\xa8\xef\xb7\xa9\xef\xb7\xaa\xef\xb7\xab\xef\xb7" + "\xac\xef\xb7\xad\xef\xb7\xae\xef\xb7\xaf") + run(name, name) + def testLongName(self): test = DummyTest("test", "a" * 256, base_logdir=self.tmpdir) self.assertEqual(os.path.basename(test.logdir), "a" * 250)