mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Path standardisation tweaks
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32328 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
c11dbf7f6a
commit
9550a5415b
2 changed files with 18 additions and 17 deletions
|
@ -4405,38 +4405,31 @@ static NSFileManager *fm = nil;
|
|||
{
|
||||
BOOL atEnd = (NSMaxRange(r) == l) ? YES : NO;
|
||||
|
||||
r.location--;
|
||||
r.length++;
|
||||
if (r.location > root)
|
||||
{
|
||||
NSRange r2 = {root, r.location-root};
|
||||
NSRange r2;
|
||||
|
||||
r.location--;
|
||||
r.length++;
|
||||
r2 = NSMakeRange(root, r.location-root);
|
||||
r = [s rangeOfCharacterFromSet: pathSeps()
|
||||
options: NSBackwardsSearch
|
||||
range: r2];
|
||||
if (r.length == 0)
|
||||
{
|
||||
r = r2;
|
||||
r = r2; // Location just after root
|
||||
r.length++;
|
||||
}
|
||||
else
|
||||
{
|
||||
r.length = NSMaxRange(r2) - r.location;
|
||||
r.location++; // Location Just after last separator
|
||||
}
|
||||
if (YES == atEnd)
|
||||
{
|
||||
r.length += 3; /* Add the `/..' */
|
||||
}
|
||||
else
|
||||
{
|
||||
r.length += 4; /* Add the `/../' */
|
||||
}
|
||||
r.length += 2; // Add the `..'
|
||||
}
|
||||
else
|
||||
if (NO == atEnd)
|
||||
{
|
||||
/* Don't remove the root itsself.
|
||||
*/
|
||||
r.location++;
|
||||
r.length--;
|
||||
r.length++; // Add the '/' after the '..'
|
||||
}
|
||||
[s deleteCharactersInRange: r];
|
||||
l -= r.length;
|
||||
|
|
|
@ -250,6 +250,14 @@ int main()
|
|||
PASS_EQUAL([@"/home/../nicola" stringByStandardizingPath], @"/nicola",
|
||||
"/home/../nicola stringByStandardizingPath == /nicola");
|
||||
|
||||
PASS_EQUAL([@"/here/and/there/../../nicola" stringByStandardizingPath],
|
||||
@"/here/nicola",
|
||||
"/here/and/there/../../nicola stringByStandardizingPath == /here/nicola");
|
||||
|
||||
PASS_EQUAL([@"/here/../../nicola" stringByStandardizingPath],
|
||||
@"/nicola",
|
||||
"/here/../../nicola stringByStandardizingPath == /nicola");
|
||||
|
||||
PASS_EQUAL([@"home/../nicola" stringByStandardizingPath], @"home/../nicola",
|
||||
"home/../nicola stringByStandardizingPath == home/../nicola");
|
||||
|
||||
|
|
Loading…
Reference in a new issue