diff --git a/ChangeLog b/ChangeLog index 1da3ba2f1..5f6ff826b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2012-08-27 Richard Frith-Macdonald + + * Source/NSSstring.m: ([-stringByAppendingPathComponent:]) fix for + append to an empty string with a windows path as an argument. + 2012-08-26 Niels Grewe * configure.ac: Check for sys/filio.h and whether we need to diff --git a/Source/NSString.m b/Source/NSString.m index 804388b8f..de7d6dc01 100644 --- a/Source/NSString.m +++ b/Source/NSString.m @@ -3846,33 +3846,7 @@ static NSFileManager *fm = nil; unsigned root; unichar buf[length+aLength+1]; - /* If the 'component' has a leading path separator (or drive spec - * in windows) then we need to find its length so we can strip it. - */ root = rootOf(aString, aLength); - if (root > 0) - { - unichar c = [aString characterAtIndex: 0]; - - if (c == '~') - { - root = 0; - } - else if (root > 1 && pathSepMember(c)) - { - int i; - - for (i = 1; i < root; i++) - { - c = [aString characterAtIndex: i]; - if (!pathSepMember(c)) - { - break; - } - } - root = i; - } - } if (length == 0) { @@ -3881,6 +3855,33 @@ static NSFileManager *fm = nil; } else { + /* If the 'component' has a leading path separator (or drive spec + * in windows) then we need to find its length so we can strip it. + */ + if (root > 0) + { + unichar c = [aString characterAtIndex: 0]; + + if (c == '~') + { + root = 0; + } + else if (root > 1 && pathSepMember(c)) + { + int i; + + for (i = 1; i < root; i++) + { + c = [aString characterAtIndex: i]; + if (!pathSepMember(c)) + { + break; + } + } + root = i; + } + } + [self getCharacters: buf range: ((NSRange){0, length})]; /* We strip back trailing path separators, and replace them with @@ -3912,36 +3913,42 @@ static NSFileManager *fm = nil; root = rootOf(self, originalLength); } - // Trim trailing path separators - while (length > 1 && pathSepMember(buf[length-1]) == YES) - { - length--; - } - - /* Trim multi separator sequences outside root (root may contain an - * initial // pair if it is a windows UNC path). - */ if (length > 0) { + /* Trim trailing path separators as long as they are not part of + * the root. + */ aLength = length - 1; - while (aLength > root) + while (aLength > root && pathSepMember(buf[aLength]) == YES) { - if (pathSepMember(buf[aLength]) == YES) - { - buf[aLength] = pathSepChar(); - if (pathSepMember(buf[aLength-1]) == YES) - { - unsigned pos; - - buf[aLength-1] = pathSepChar(); - for (pos = aLength+1; pos < length; pos++) - { - buf[pos-1] = buf[pos]; - } - length--; - } - } aLength--; + length--; + } + + /* Trim multi separator sequences outside root (root may contain an + * initial // pair if it is a windows UNC path). + */ + if (length > 0) + { + while (aLength > root) + { + if (pathSepMember(buf[aLength]) == YES) + { + buf[aLength] = pathSepChar(); + if (pathSepMember(buf[aLength-1]) == YES) + { + unsigned pos; + + buf[aLength-1] = pathSepChar(); + for (pos = aLength+1; pos < length; pos++) + { + buf[pos-1] = buf[pos]; + } + length--; + } + } + aLength--; + } } } return [NSStringClass stringWithCharacters: buf length: length];