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

[5.2] com_users: Simplifying empty check in login layout #41677

Merged
merged 4 commits into from
May 7, 2024

Conversation

Hackwar
Copy link
Member

@Hackwar Hackwar commented Sep 8, 2023

Summary of Changes

I fixed bugs in an old layout override and stumbled over this. This is a very complex way of checking if there is anything in that parameter. We could make it worse by using regex and maybe doing an !empty() check around all of this... Anyway, this check just tries to find out if the description parameter does contain anything of relevance. Relevant is everything that remains after removing spaces from beginning and end of the string, thus a trim() is enough.

Testing Instructions

Codereview

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

@brianteeman
Copy link
Contributor

if you look in the history you will see that it was deliberately changed from what you are proposing to what it is now

@Hackwar
Copy link
Member Author

Hackwar commented Sep 8, 2023

The PR in question is #9896. Even looking at the PR, I can't understand why this was merged. Regardless of that, the browser in question is EOL and not supported by us anymore. I still think that this PR is the right way to go.

@richard67
Copy link
Member

if you look in the history you will see that it was deliberately changed from what you are proposing to what it is now

When reading that old PR‘s code changes I can’t see that it had any trim before. It was comparing the complete unmodified string. So this PR here is not a roll back of the changes from the other PR.

richard67
richard67 previously approved these changes Sep 9, 2023
Copy link
Member

@richard67 richard67 left a comment

Choose a reason for hiding this comment

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

The purpose of the code is to rule out strings which contains only spaces. For this case, the proposed code has the same result, is more effective and better readable.

@richard67
Copy link
Member

@Hackwar If you want to make it work exactly the same way as the old code regarding other kinds of white space than a single space character, you could use a string with a single space as 2nd parameter for trim, then it would trim only space characters. Not sure if it needs that, but we would play safe and it still has all advantages of your code change.

@HLeithner
Copy link
Member

interesting your change changes the behavior more then I expected:

https://3v4l.org/7LM6I (yours is $z)

@richard67
Copy link
Member

Hmm, the zero evaluates to false, too. Indeed a change.

@richard67 richard67 dismissed their stale review September 9, 2023 10:36

Seems I was not looking close enough.

@brianteeman
Copy link
Contributor

This is why it is always important to look at why code was written the way that it was before changing it

@HLeithner
Copy link
Member

my suggestion is to move it to !empty(trim($value))

@Hackwar
Copy link
Member Author

Hackwar commented Sep 14, 2023

Yes, this "changes" behavior. It actually fixes it to be in line with what people expect. The goal is to only show the text when it contains anything. Right now it only removes spaces, but would keep a line break or tab and then show the text. Yes, it also hides it, when the content is only a 0, but I would also argue, that there is no situation where someone would want a single 0 as description. The goal of this PR is to simplify the code and make it readable for people. We want to remove invisible characters of all kinds, so I'm not going to limit the functionality of trim() to just remove spaces. If that is not acceptable, then rather lets close this PR than to waste more time on this.

@HLeithner HLeithner changed the base branch from 5.0-dev to 5.1-dev September 30, 2023 22:48
@HLeithner
Copy link
Member

This pull request has been automatically rebased to 5.1-dev.

@Hackwar Hackwar added the PBF Pizza, Bugs and Fun label Feb 20, 2024
@Hackwar Hackwar changed the title [5.0] com_users: Simplifying empty check in login layout [5.1] com_users: Simplifying empty check in login layout Feb 21, 2024
@adj9
Copy link

adj9 commented Feb 24, 2024

Seeing the logic comes back with the summary. However, it is not possible for me to perform a test.
Seeing the documentation of PHP trim function, it cleans up all types of blank spaces in a string.

@lucasacchiricciardi
Copy link

I have tested this item ✅ successfully on 7ca9182

I have read the code proposed in the PR, and I have checked the PHP documentation (https://www.php.net/manual/en/function.trim.php). The PR certainly brings an advantage: it recognizes and removes not only empty spaces but also other hidden special characters.

" " (ASCII 32 (0x20)), an ordinary space.
"\t" (ASCII 9 (0x09)), a tab.
"\n" (ASCII 10 (0x0A)), a new line (line feed).
"\r" (ASCII 13 (0x0D)), a carriage return.
"\0" (ASCII 0 (0x00)), the NUL-byte.
"\v" (ASCII 11 (0x0B)), a vertical tab.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/41677.

@Hackwar Hackwar added the RTC This Pull Request is Ready To Commit label Feb 26, 2024
@bembelimen bembelimen removed the RTC This Pull Request is Ready To Commit label Mar 2, 2024
@viocassel
Copy link
Contributor

I have tested this item ✅ successfully on 7ca9182


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/41677.

@Quy Quy removed PBF Pizza, Bugs and Fun PR-5.1-dev labels Mar 29, 2024
@Quy
Copy link
Contributor

Quy commented Mar 29, 2024

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/41677.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Mar 29, 2024
@Quy Quy added PR-5.1-dev and removed PR-5.0-dev labels Mar 29, 2024
@HLeithner HLeithner changed the base branch from 5.1-dev to 5.2-dev April 24, 2024 09:07
@HLeithner
Copy link
Member

This pull request has been automatically rebased to 5.2-dev.

@HLeithner HLeithner changed the title [5.1] com_users: Simplifying empty check in login layout [5.2] com_users: Simplifying empty check in login layout Apr 24, 2024
@pe7er pe7er enabled auto-merge (squash) May 7, 2024 07:31
@pe7er pe7er self-assigned this May 7, 2024
@pe7er pe7er merged commit 17f2d5c into joomla:5.2-dev May 7, 2024
3 checks passed
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label May 7, 2024
@pe7er
Copy link
Contributor

pe7er commented May 7, 2024

Thanks @Hackwar !

@Quy Quy removed the PR-5.1-dev label May 7, 2024
@Quy Quy added this to the Joomla! 5.2.0 milestone May 7, 2024
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.

None yet