tester("ntpath.normpath('..')", r'..')
tester("ntpath.normpath('.')", r'.')
+ tester("ntpath.normpath('c:.')", 'c:')
tester("ntpath.normpath('')", r'.')
tester("ntpath.normpath('/')", '\\')
tester("ntpath.normpath('c:/')", 'c:\\')
tester("ntpath.normpath('/../.././..')", '\\')
tester("ntpath.normpath('c:/../../..')", 'c:\\')
+ tester("ntpath.normpath('/./a/b')", r'\a\b')
+ tester("ntpath.normpath('c:/./a/b')", r'c:\a\b')
tester("ntpath.normpath('../.././..')", r'..\..\..')
tester("ntpath.normpath('K:../.././..')", r'K:..\..\..')
+ tester("ntpath.normpath('./a/b')", r'a\b')
+ tester("ntpath.normpath('c:./a/b')", r'c:a\b')
tester("ntpath.normpath('C:////a/b')", r'C:\a\b')
tester("ntpath.normpath('//machine/share//a/b')", r'\\machine\share\a\b')
("/.", "/"),
("/./", "/"),
("/.//.", "/"),
+ ("/./foo/bar", "/foo/bar"),
("/foo", "/foo"),
("/foo/bar", "/foo/bar"),
("//", "//"),
("///..//./foo/.//bar", "/foo/bar"),
(".", "."),
(".//.", "."),
+ ("./foo/bar", "foo/bar"),
("..", ".."),
("../", ".."),
("../foo", "../foo"),
--- /dev/null
+Fix :func:`os.path.normpath` for drive-relative paths on Windows.
#endif
#define SEP_OR_END(x) (IS_SEP(x) || IS_END(x))
- if (p1[0] == L'.' && IS_SEP(&p1[1])) {
- // Skip leading '.\'
- path = &path[2];
- while (IS_SEP(path)) {
- path++;
- }
- p1 = p2 = minP2 = path;
- lastC = SEP;
- }
- else {
- Py_ssize_t drvsize, rootsize;
- _Py_skiproot(path, size, &drvsize, &rootsize);
- if (drvsize || rootsize) {
- // Skip past root and update minP2
- p1 = &path[drvsize + rootsize];
+ Py_ssize_t drvsize, rootsize;
+ _Py_skiproot(path, size, &drvsize, &rootsize);
+ if (drvsize || rootsize) {
+ // Skip past root and update minP2
+ p1 = &path[drvsize + rootsize];
#ifndef ALTSEP
- p2 = p1;
+ p2 = p1;
#else
- for (; p2 < p1; ++p2) {
- if (*p2 == ALTSEP) {
- *p2 = SEP;
- }
+ for (; p2 < p1; ++p2) {
+ if (*p2 == ALTSEP) {
+ *p2 = SEP;
}
+ }
#endif
- minP2 = p2 - 1;
- lastC = *minP2;
+ minP2 = p2 - 1;
+ lastC = *minP2;
#ifdef MS_WINDOWS
- if (lastC != SEP) {
- minP2++;
- }
+ if (lastC != SEP) {
+ minP2++;
+ }
+#endif
+ }
+ if (p1[0] == L'.' && SEP_OR_END(&p1[1])) {
+ // Skip leading '.\'
+ lastC = *++p1;
+#ifdef ALTSEP
+ if (lastC == ALTSEP) {
+ lastC = SEP;
+ }
#endif
+ while (IS_SEP(p1)) {
+ p1++;
}
}