Skip to content

Commit 4af4a86

Browse files
authored
Merge pull request #24 from imageworks/issue_20_deadlock_in_split_path
accepting fix proposed in issue #20 - for deadlock in path split when…
2 parents 20dac44 + 8c0f173 commit 4af4a86

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

pystring.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,8 @@ namespace path
13471347

13481348
// set i to index beyond p's last slash
13491349
int i = (int)p.size();
1350-
1350+
1351+
// walk back to find the index of the first slash from the end
13511352
while(i>0 && (p[i-1] != '\\') && (p[i-1] != '/'))
13521353
{
13531354
i = i - 1;
@@ -1361,7 +1362,7 @@ namespace path
13611362
while(!head2.empty() && ((pystring::slice(head2,-1) == "/") ||
13621363
(pystring::slice(head2,-1) == "\\")))
13631364
{
1364-
head2 = pystring::slice(head,0,-1);
1365+
head2 = pystring::slice(head2,0,-1);
13651366
}
13661367

13671368
if(!head2.empty()) head = head2;

test.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,9 @@ PYSTRING_ADD_TEST(pystring_os_path, split)
624624
split_posix(head, tail, "/a"); PYSTRING_CHECK_EQUAL(head, "/" ); PYSTRING_CHECK_EQUAL(tail, "a" );
625625
split_posix(head, tail, "/a/b/"); PYSTRING_CHECK_EQUAL(head, "/a/b" ); PYSTRING_CHECK_EQUAL(tail, "" );
626626
split_posix(head, tail, "/a/b"); PYSTRING_CHECK_EQUAL(head, "/a" ); PYSTRING_CHECK_EQUAL(tail, "b" );
627+
split_posix(head, tail, "/a/b//"); PYSTRING_CHECK_EQUAL(head, "/a/b" ); PYSTRING_CHECK_EQUAL(tail, "" );
628+
split_posix(head, tail, "/a/b/////////////"); PYSTRING_CHECK_EQUAL(head, "/a/b" ); PYSTRING_CHECK_EQUAL(tail, "" );
629+
627630

628631
split_nt(head, tail, ""); PYSTRING_CHECK_EQUAL(head, "" ); PYSTRING_CHECK_EQUAL(tail, "" );
629632
split_nt(head, tail, "\\"); PYSTRING_CHECK_EQUAL(head, "\\" ); PYSTRING_CHECK_EQUAL(tail, "" );
@@ -632,6 +635,8 @@ PYSTRING_ADD_TEST(pystring_os_path, split)
632635
split_nt(head, tail, "c:\\a"); PYSTRING_CHECK_EQUAL(head, "c:\\" ); PYSTRING_CHECK_EQUAL(tail, "a" );
633636
split_nt(head, tail, "c:\\a\\b"); PYSTRING_CHECK_EQUAL(head, "c:\\a" ); PYSTRING_CHECK_EQUAL(tail, "b" );
634637
split_nt(head, tail, "c:\\a\\b\\"); PYSTRING_CHECK_EQUAL(head, "c:\\a\\b" ); PYSTRING_CHECK_EQUAL(tail, "" );
638+
split_nt(head, tail, "D:\\dir\\\\"); PYSTRING_CHECK_EQUAL(head, "D:\\dir" ); PYSTRING_CHECK_EQUAL(tail, "" );
639+
635640
}
636641

637642
PYSTRING_ADD_TEST(pystring_os_path, splitext)

0 commit comments

Comments
 (0)