##// END OF EJS Templates
dirs: reject consecutive slashes in paths...
Augie Fackler -
r43799:5d40317d default
parent child Browse files
Show More
@@ -0,0 +1,27 b''
1 from __future__ import absolute_import
2
3 import unittest
4
5 import silenttestrunner
6
7 from mercurial import util
8
9
10 class dirstests(unittest.TestCase):
11 def testdirs(self):
12 for case, want in [
13 (b'a/a/a', [b'a', b'a/a', b'']),
14 (b'alpha/beta/gamma', [b'', b'alpha', b'alpha/beta']),
15 ]:
16 d = util.dirs({})
17 d.addpath(case)
18 self.assertEqual(sorted(d), sorted(want))
19
20 def testinvalid(self):
21 with self.assertRaises(ValueError):
22 d = util.dirs({})
23 d.addpath(b'a//b')
24
25
26 if __name__ == '__main__':
27 silenttestrunner.main(__name__)
@@ -66,6 +66,14 b' static int _addpath(PyObject *dirs, PyOb'
66 while ((pos = _finddir(cpath, pos - 1)) != -1) {
66 while ((pos = _finddir(cpath, pos - 1)) != -1) {
67 PyObject *val;
67 PyObject *val;
68
68
69 /* Sniff for trailing slashes, a marker of an invalid input. */
70 if (pos > 0 && cpath[pos - 1] == '/') {
71 PyErr_SetString(
72 PyExc_ValueError,
73 "found invalid consecutive slashes in path");
74 goto bail;
75 }
76
69 key = PyBytes_FromStringAndSize(cpath, pos);
77 key = PyBytes_FromStringAndSize(cpath, pos);
70 if (key == NULL)
78 if (key == NULL)
71 goto bail;
79 goto bail;
@@ -3515,6 +3515,10 b' class dirs(object):'
3515 def addpath(self, path):
3515 def addpath(self, path):
3516 dirs = self._dirs
3516 dirs = self._dirs
3517 for base in finddirs(path):
3517 for base in finddirs(path):
3518 if base.endswith(b'/'):
3519 raise ValueError(
3520 "found invalid consecutive slashes in path: %r" % base
3521 )
3518 if base in dirs:
3522 if base in dirs:
3519 dirs[base] += 1
3523 dirs[base] += 1
3520 return
3524 return
General Comments 0
You need to be logged in to leave comments. Login now