Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/IO/Path.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static partial class Path
// the specified extension. If path is null, the function
// returns null. If path does not contain a file extension,
// the new file extension is appended to the path. If extension
// is null, any existing extension is removed from path.
// is null or empty, any existing extension is removed from path.
[return: NotNullIfNotNull(nameof(path))]
public static string? ChangeExtension(string? path, string? extension)
{
Expand All @@ -64,7 +64,7 @@ public static partial class Path
}
}

if (extension == null)
if (string.IsNullOrEmpty(extension))
{
return path.Substring(0, subLength);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class File_ChangeExtension : FileSystemTest
[InlineData("", ".tmp", "")]
[InlineData(null, ".tmp", null)]
[InlineData("filename", ".tmp", "filename.tmp")]
[InlineData("filename.tmp", "", "filename.")]
[InlineData("filename.tmp", "", "filename")]
[InlineData("filename.tmp", "...", "filename...")]
[InlineData("filename.tmp", null, "filename")]
[InlineData("filename.tmp.doc", ".tmp", "filename.tmp.tmp")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public class PathTests : PathTestsBase
InlineData(null, "exe", null),
InlineData("", "", ""),
InlineData("file.exe", null, "file"),
InlineData("file.exe", "", "file."),
InlineData("file.exe", "", "file"),
InlineData("file", null, "file"),
InlineData("file", "", "file"),
InlineData("file", "exe", "file.exe"),
InlineData("file", ".exe", "file.exe"),
InlineData("file.txt", "exe", "file.exe"),
Expand Down