Skip to content
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

Replace Path class with Symfony Path class #11340

Closed
2 tasks done
emteknetnz opened this issue Aug 18, 2024 · 4 comments
Closed
2 tasks done

Replace Path class with Symfony Path class #11340

emteknetnz opened this issue Aug 18, 2024 · 4 comments
Assignees

Comments

@emteknetnz
Copy link
Member

emteknetnz commented Aug 18, 2024

Path could be possibly be replaced with the Path class in symfony/filesystem

Notes

  • If we can simply swap it out and no unit tests break, then do the work directly in CMS 5 instead. Otherwise if we need to update the code that calls these methods, then target CMS 6

Acceptance criteria

  • Determine if replacing the Silverstripe Path class is worthwhile and viable
  • Deprecate and replace Path

CMS 5 PRs

CMS 6 PRs

Do not merge yet - after CMS 5 PR is merged, reassign to Guy to rebase.

@emteknetnz
Copy link
Member Author

emteknetnz commented Aug 19, 2024

I don't think this is worthwhile as the Silverstripe Path methods having additional logic which symfony path does not

Silverstripe Path::join() includes protection against directly traversal i.e. not allowed .. and will throw an exception, whereas Symfony Path will not stop you from having a path with '..' and will simply return a path with the the .. resolved for you - "all "." and ".." segments are removed as far as possible"

The Silverstripe normalize() method also has an additional param $relative which means that the directory seperators will be rtrim()'ed off

If you agree with this assessment then just close this issue

@emteknetnz emteknetnz reopened this Aug 19, 2024
@emteknetnz emteknetnz removed their assignment Aug 19, 2024
@GuySartorelli GuySartorelli self-assigned this Aug 20, 2024
@GuySartorelli
Copy link
Member

Silverstripe Path::join() includes protection against directly traversal i.e. not allowed .. and will throw an exception, whereas Symfony Path will not stop you from having a path with '..' and will simply return a path with the the .. resolved for you - "all "." and ".." segments are removed as far as possible"

I honestly think the way symfony does that is better. Directory traversal protection doesn't belong in a "join these two paths together" method, it belongs in whatever is using that path - at which point you'd know where you are or aren't allowed to traverse to.
If I go Path::join('_resources/theme/simple/images/', '../css/'); I should be able to get '_resources/theme/simple/css/' as a result without an error thrown in my face for trying to get a perfectly valid path.

The Silverstripe normalize() method also has an additional param $relative which means that the directory seperators will be rtrim()'ed off

I think it's worth losing that little bit of functionality and having a few ltrim(Path::normalize($myPath), '/'); around the place for the sake of

  1. not having any confusion at all about which Path class to use, because there's only one
  2. IMO better join functionality
  3. All of the additional methods symfony has on their Path class

And yes technically we can use the other Path class along side our one, but that just makes point 1 worse imo.

@emteknetnz emteknetnz removed their assignment Aug 20, 2024
@michalkleiner
Copy link
Contributor

I'd go with Symphony's Path class, too, so that we don't have the same conversation in a year why we didn't replace this component when we replaced others.

@GuySartorelli
Copy link
Member

#11380 (review)
We're not doing it I guess

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

No branches or pull requests

3 participants