? Success

User tests: Successful: Unsuccessful:

avatar bweston92
bweston92
28 Oct 2014

Trim search string input fixes #4945

Votes

# of Users Experiencing Issue
1/1
Average Importance Score
2.00

avatar bweston92 bweston92 - open - 28 Oct 2014
avatar jissues-bot jissues-bot - change - 28 Oct 2014
Labels Added: ?
avatar infograf768
infograf768 - comment - 28 Oct 2014

See comment on issues

avatar Kubik-Rubik Kubik-Rubik - change - 28 Oct 2014
Status Pending Needs Review
avatar Kubik-Rubik
Kubik-Rubik - comment - 28 Oct 2014

Please fix the following errors:

  • Travis failed
  • Fatal errror - $input is not defined

Thanks!

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

avatar joomdonation
joomdonation - comment - 28 Oct 2014

Personal, I like the the original commit of this PR than the later commit. The reasons is because:

  1. It is sorter and simpler.

  2. I solve the actual problem (just to prevent we include white space in the search string by mistake). Agree that JFilterInput will clean remove the multibyte white spaces. However, for simple use-case like that, I think php native trim function would be enough:

  3. We just use it to prevent white space added to search string by "accident"
  4. I think the reason we have to use JFilterInput clean for username just to prevent users from trying to make their username looks the same with an exist one (they try/attemp to do that while in this case, we just prevent users from including the space by accident).
  5. I think it is difficult to to enter multibyte white spaces unless you really want to do. For me, I had to google to see how to enter it when I tested the JFilterInput clean with TRIM parameter :D

Not sure how other developers think about it.
.

avatar Bakual
Bakual - comment - 28 Oct 2014

@joomdonation Personally I agree with you. The code looks not nice for such a trivial task.
However I also have to say that it could be done easier in this case. Instead of creating a new method where you have to get the JInput object again, you could just add a line:

$searchstring = $this->_db->quote('%' . $input->getString('searchstring') . '%');
$searchstring = JFilterInput::getInstance()->clean($searchstring, 'TRIM');
avatar joomdonation
joomdonation - comment - 28 Oct 2014

@Bakual Agree with your last comment, too. That's what I wanted to say, too. If we want to use JFilterInput, just use the code which you proposed, not creating a new method. Could @bweston92 please update the code as @Bakual proposed ? Then I think we will all be happy :).

avatar bweston92
bweston92 - comment - 28 Oct 2014

@joomdonation @Bakual suggestion doesn't work. Once the percent symbols are around the string it will not trim the white-space within.

The fact I abstracted it into another method is because I didn't want to clutter the code in the search method. Having to do a static call etc is ugly anyhow.

avatar bweston92
bweston92 - comment - 28 Oct 2014

Updated, still don't know why PHP's trim isn't sufficient.

avatar joomdonation
joomdonation - comment - 28 Oct 2014

@bweston92 : Yes, sorry, you are correct. The code @Bakual proposed doesn't work, but it gives the idea how we would like the code looks like if we need to use JFilterInput.

As I mentioned in my first comment, I am OK with use PHP native trim method for this case. Maybe @Bakual can give final decision?

avatar bweston92
bweston92 - comment - 28 Oct 2014

Well the code uses the filter way of things, I think it's had enough commits for a tiny update.

avatar Bakual
Bakual - comment - 28 Oct 2014

Sorry about the wrong code. I just copy pasted :smile:

Updated, still don't know why PHP's trim isn't sufficient.

Thanks. Code looks fine now.
Reason is because it would not work for chines/asian people. It's just better this way and since we recently introduced this new filter it makes sense to use it over trim.

avatar bweston92
bweston92 - comment - 28 Oct 2014

Ok, merge when you're ready.

avatar infograf768
infograf768 - comment - 29 Oct 2014

@test
Fine here. thanks

avatar infograf768 infograf768 - close - 29 Oct 2014
avatar infograf768 infograf768 - change - 29 Oct 2014
Title
Trim search string input
Trim search string input in language overrides
Status Needs Review Closed
Closed_Date 0000-00-00 00:00:00 2014-10-29 06:54:40

Add a Comment

Login with GitHub to post a comment