Skip to content

Path.ChangeExtension with an empty string behaves differently on Linux and Windows platforms #100687

Closed
@jasonleenaylor

Description

@jasonleenaylor

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

string.Concat(subpath, ".", extension);

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.IOneeds-author-actionAn issue or pull request that requires more info or actions from the author.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions