mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
fix bug appending path to empty string on windows
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@35462 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
543be7f837
commit
739c0c8ece
2 changed files with 63 additions and 51 deletions
|
@ -1,3 +1,8 @@
|
|||
2012-08-27 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSSstring.m: ([-stringByAppendingPathComponent:]) fix for
|
||||
append to an empty string with a windows path as an argument.
|
||||
|
||||
2012-08-26 Niels Grewe <niels.grewe@halbordnung.de>
|
||||
|
||||
* configure.ac: Check for sys/filio.h and whether we need to
|
||||
|
|
|
@ -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];
|
||||
|
|
Loading…
Reference in a new issue