summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeremy Kuhne <jeremy.kuhne@microsoft.com>2018-06-15 03:12:28 (GMT)
committerJeremy Kuhne <jeremy.kuhne@microsoft.com>2018-06-27 00:06:57 (GMT)
commitd644d8a7d9484f994d75b02fde99393707b280de (patch)
treef425b09213589c993e327978455d6076c3934704 /src
parented65cca4838f23617c359ba83098e0ed5bad8a8f (diff)
downloadcoreclr-d644d8a7d9484f994d75b02fde99393707b280de.zip
coreclr-d644d8a7d9484f994d75b02fde99393707b280de.tar.gz
coreclr-d644d8a7d9484f994d75b02fde99393707b280de.tar.bz2
Fix handling of generating relative path to parent (#18460)
Fixes #30263
Diffstat (limited to 'src')
-rw-r--r--src/mscorlib/shared/System/IO/Path.cs22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/mscorlib/shared/System/IO/Path.cs b/src/mscorlib/shared/System/IO/Path.cs
index 1e40ab5..d92df5a 100644
--- a/src/mscorlib/shared/System/IO/Path.cs
+++ b/src/mscorlib/shared/System/IO/Path.cs
@@ -731,13 +731,14 @@ namespace System.IO
// Add parent segments for segments past the common on the "from" path
if (commonLength < relativeToLength)
{
- sb.Append(PathInternal.ParentDirectoryPrefix);
+ sb.Append("..");
- for (int i = commonLength; i < relativeToLength; i++)
+ for (int i = commonLength + 1; i < relativeToLength; i++)
{
if (PathInternal.IsDirectorySeparator(relativeTo[i]))
{
- sb.Append(PathInternal.ParentDirectoryPrefix);
+ sb.Append(DirectorySeparatorChar);
+ sb.Append("..");
}
}
}
@@ -749,11 +750,20 @@ namespace System.IO
}
// Now add the rest of the "to" path, adding back the trailing separator
- int count = pathLength - commonLength;
+ int differenceLength = pathLength - commonLength;
if (pathEndsInSeparator)
- count++;
+ differenceLength++;
+
+ if (differenceLength > 0)
+ {
+ if (sb.Length > 0)
+ {
+ sb.Append(DirectorySeparatorChar);
+ }
+
+ sb.Append(path, commonLength, differenceLength);
+ }
- sb.Append(path, commonLength, count);
return StringBuilderCache.GetStringAndRelease(sb);
}