8000 [Filesystem] Add Path::normalizeForCurrentOs() for platform-aware normalization by Exsol · Pull Request #63216 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@Exsol
Copy link
@Exsol Exsol commented Jan 27, 2026
Q A
Branch? 6.4
Bug fix? no
New feature? yes
Deprecations? no
Issues Fix #60949
License MIT

Description

On Unix-like systems, backslash (\) is a valid character in filenames, not a directory separator. The existing Path::normalize() method always replaces backslashes with forward slashes for cross-platform compatibility.

This PR adds a new method Path::normalizeForCurrentOs() that:

  • On Windows: replaces backslashes with forward slashes (same as normalize())
  • On Unix: preserves backslashes since they are valid filename characters

Why a new method instead of fixing normalize()?

Changing normalize() behavior would break backward compatibility. The current behavior is documented and intentional for cross-platform path handling. Adding a new method allows users who need platform-aware normalization to opt-in while preserving BC.

Usage

// Cross-platform normalization (existing behavior)
Path::normalize('foo\bar'); // => 'foo/bar' on all platforms

// Platform-aware normalization (new)
Path::normalizeForCurrentOs('foo\bar');
// => 'foo/bar' on Windows
// => 'foo\bar' on Unix (backslash preserved)

…malization

On Unix-like systems, backslash is a valid character in filenames, not a
directory separator. The existing normalize() method always replaces
backslashes for cross-platform compatibility.

This adds a new method that only normalizes backslashes on Windows,
preserving them on Unix where they may be part of filenames.
@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 8.1 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@nicolas-grekas
Copy link
Member
nicolas-grekas commented Jan 27, 2026

Bad idea sorry. realpath() is the way to go. Not all paths are system paths, so that this makes a wrong assumption.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0