-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Path.ChangeExtension with an empty string behaves differently on Linux and Windows platforms #100687
Comments
- When ChangeExtension is called with an empty string completely remove the extension instead of adding a '.'
@vcsjones or anyone I am happy to make a PR for this, but I would like to add a unit test. Can you help me locate other unit tests for System.IO? |
@jasonleenaylor Tests: runtime/src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/IO/PathTests.cs Lines 13 to 34 in d79a753
|
- When ChangeExtension is called with an empty string completely remove the extension instead of adding a '.'
Console.WriteLine(Path.ChangeExtension("file.extension", null));
Console.WriteLine(Path.ChangeExtension("file.extension", "")); prints
On .NET Framework, .NET 8 on Windows and .NET 8 on Linux. |
@MihaZupan Hmm, we saw this issue when running in .NET 6 on Windows, and .NET 6 on Linux. It added the period on Linux, but not on Windows. |
As @MihaZupan described, this isn't inconsistent between OSes, and it works as documented, including .NET 6.
Can you please double check if you are really passing |
This issue has been marked |
This issue has been automatically marked |
This issue will now be closed since it had been marked |
Description
We have a cross platform application running on Windows and Linux and we noticed a difference between the
ChangeExtension implementation on the two platforms. On Windows calling ChangeExtension with an empty string results in the extension being removed. e.g. "file.extension" becomes "file" but on Linux we get "file."
On windows it must be running the framework version of this code but on Linux we get the core runtime implementation.
Reproduction Steps
Run Path.ChangeExtension("file.extension", "") on Windows and Linux
Expected behavior
The extension is removed leaving a bare file name with no trailing '.'
Actual behavior
The extension is removed leaving a trailing '.'
Regression?
This works as described in .NET Framework
Known Workarounds
Users can use Path.RemoveExtension instead when removing, but if you are adding an optional extension the only workaround is to add a test for empty before using the method
Configuration
No response
Other information
runtime/src/libraries/System.Private.CoreLib/src/System/IO/Path.cs
Line 75 in 068ba8e
The text was updated successfully, but these errors were encountered: