Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Finder] sortByName inconsistent results depending on platform #58375

Open
@jnvsor

Description

@jnvsor

Symfony version(s) affected

v7.1.4

Description

Symfony finder allows the user to manipulate files with / regardless of environment, but because / and \ are in different parts of the ASCII table the results of sortByName are inconsistent depending on platform.

How to reproduce

mkdir('Folder');
touch('FolderBase.php');
touch('Folder/Sub.php');

$files = Symfony\Component\Finder\Finder::create()->files()->in(['Folder'])->append(['FolderBase.php'])->sortByName();
foreach ($files as $file) {
  echo (string) $file.PHP_EOL;
}

Possible Solution

Normalize paths in SortableIterator

Additional Context

Linux output:

Folder/Sub.php
FolderBase.php

Windows output:

FolderBase.php
Folder\Sub.php

First reproduced at kint-php/kint#425

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions