mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-17 19:21:56 +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
d4e6a1d1fd
commit
bdec3a0c48
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>
|
2012-08-26 Niels Grewe <niels.grewe@halbordnung.de>
|
||||||
|
|
||||||
* configure.ac: Check for sys/filio.h and whether we need to
|
* configure.ac: Check for sys/filio.h and whether we need to
|
||||||
|
|
|
@ -3846,33 +3846,7 @@ static NSFileManager *fm = nil;
|
||||||
unsigned root;
|
unsigned root;
|
||||||
unichar buf[length+aLength+1];
|
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);
|
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)
|
if (length == 0)
|
||||||
{
|
{
|
||||||
|
@ -3881,6 +3855,33 @@ static NSFileManager *fm = nil;
|
||||||
}
|
}
|
||||||
else
|
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})];
|
[self getCharacters: buf range: ((NSRange){0, length})];
|
||||||
|
|
||||||
/* We strip back trailing path separators, and replace them with
|
/* We strip back trailing path separators, and replace them with
|
||||||
|
@ -3912,36 +3913,42 @@ static NSFileManager *fm = nil;
|
||||||
root = rootOf(self, originalLength);
|
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)
|
if (length > 0)
|
||||||
{
|
{
|
||||||
|
/* Trim trailing path separators as long as they are not part of
|
||||||
|
* the root.
|
||||||
|
*/
|
||||||
aLength = length - 1;
|
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--;
|
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];
|
return [NSStringClass stringWithCharacters: buf length: length];
|
||||||
|
|
Loading…
Reference in a new issue