diff options
Diffstat (limited to 'src/mscorlib/shared/System/IO/Path.cs')
-rw-r--r-- | src/mscorlib/shared/System/IO/Path.cs | 22 |
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 1e40ab5e60..d92df5a57e 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); } |