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

Class BaseStringHelper: optimize & bugfix #18799

Closed
wants to merge 5 commits into from
Closed

Class BaseStringHelper: optimize & bugfix #18799

wants to merge 5 commits into from

Conversation

WinterSilence
Copy link
Contributor

  • Optimize BaseStringHelper::basename(): passing normalized path to PHP basename()
  • Bugfix BaseStringHelper::dirname(): if path '/dir/sub-dir/', method return '/dir' instead '/dir/sub-dir'
Q A
Is bugfix? ✔️
New feature?
Breaks BC?
Tests pass? ✔️
Fixed issues #18798

- Optimize `BaseStringHelper::basename()`: passing normalized path to PHP `basename()`
- Bugfix `BaseStringHelper::dirname()`:

 - if path '/dir/sub-dir/', method return '/dir' instead '/dir/sub-dir'
 - if path '/dir', method return '/' instead ''

return $path;
return \basename($path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unnecessary and even wrong since basename is local aware.

Copy link
Contributor Author

@WinterSilence WinterSilence Aug 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bizley fixed

This seems unnecessary and even wrong

"seems"? maybe you test it before? it's not true and work faster - php find function in local namespace and only after it in global namespace

local aware

you mean global? (:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm referring to the "Caution" message stated at https://www.php.net/manual/en/function.basename.php

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bizley it's stupid:

  • we don't pass encoding to method
  • encoding in mb_* functions: "If it is omitted, internal character encoding is used"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WinterSilence Even with invalid encoding old implementation worked fine: https://3v4l.org/suLOs

Copy link
Contributor Author

@WinterSilence WinterSilence Aug 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rob006 you pass encoding, old implementation don't do it and use default encoding.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WinterSilence I'm passing invalid encoding just to prove you, that even with invalid encoding it is working fine...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rob006 not full implementation, just try cut $suffix = 'ЫВА-1234.doc'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rob006 is everything ok? (:

@samdark samdark added this to the 2.0.44 milestone Aug 6, 2021
$pos = mb_strrpos($path, '/');
if ($pos !== false) {
return mb_substr($path, $pos + 1);
if (!empty($suffix)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!empty($suffix) is not the same as mb_strlen($suffix) > 0 - it behaves differently if you pass "0" as $suffix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@bizley
Copy link
Member

bizley commented Aug 11, 2021

As we mentioned before this is again PR not following good practices so I'm closing it. Please extract the portion actually responsible for fixing the reported problem in separate PR. As for the so called "optimization" part - we already found some problems there and you apparently cannot admit its flaws so I suggest dropping it. But hey, you can always send another (proper) PR.

@bizley bizley closed this Aug 11, 2021
@WinterSilence
Copy link
Contributor Author

@bizley "we" is you? As I have already said, personal grievances are irrelevant here. You can try current method with path not in 'UTF-8'(you can use something like 'Windows-1251') and pass 'ФЫВА-1234.doc'.

@samdark
Copy link
Member

samdark commented Aug 11, 2021

@WinterSilence I agree with how hard is to review many things at once in a single PR. Noone questioned that there's an issue the PR is fixing. It's just doing too much at once additionally to it. Splitting PR into several PRs will make everyone's life easier a lot.

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

Successfully merging this pull request may close these issues.

4 participants