Post by redlik7 » Thu Feb 20, 2020 10:25 pm

straightlight wrote:
Thu Feb 20, 2020 10:23 pm
Rather understand the new changes than reverting back to the old ones would be better in this case since the request constructor is a library file that is totally centralized throughout the platform.
So.... Can we expect updated piece of code? I'm not skilled enough to figure this out myself, as most of the people on this forum ;D

Newbie

Posts

Joined
Thu Feb 20, 2020 3:45 pm

Post by straightlight » Thu Feb 20, 2020 10:29 pm

In request.php file, replace:

Code: Select all

$data = array_map(function($value) {
				return trim($value, ' ');
			}, $data);
with:

Code: Select all

array_walk_recursive($data, function(&$v){$v=ltrim($v);});
See if that solves the issue.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by redlik7 » Thu Feb 20, 2020 10:34 pm

straightlight wrote:
Thu Feb 20, 2020 10:29 pm
In request.php file, replace:

Code: Select all

$data = array_map(function($value) {
				return trim($value, ' ');
			}, $data);
with:

Code: Select all

array_walk_recursive($data, function(&$v){$v=ltrim($v);});
See if that solves the issue.
Will do later today, don't want to mess up the website in the middle of the day, thanks a lot anyway!

Newbie

Posts

Joined
Thu Feb 20, 2020 3:45 pm

Post by straightlight » Thu Feb 20, 2020 10:36 pm

So.... Can we expect updated piece of code? I'm not skilled enough to figure this out myself, as most of the people on this forum
Will do later today, don't want to mess up the website in the middle of the day, thanks a lot anyway!
No problem.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by straightlight » Thu Feb 20, 2020 10:44 pm

I updated the steps from the original post.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by redlik7 » Thu Feb 20, 2020 11:04 pm

straightlight wrote:
Thu Feb 20, 2020 10:44 pm
I updated the steps from the original post.
Perfect, thank you. Just out of curiosity - where is this code applied, the trimming I mean - across all fields, the backend/frontend, just the checkout fields or else?

Newbie

Posts

Joined
Thu Feb 20, 2020 3:45 pm

Post by straightlight » Fri Feb 21, 2020 2:38 am

As I replied above, the steps have been updated on my original posting: viewtopic.php?f=202&t=206658#p733037 .

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by elanclarkson » Wed Nov 10, 2021 9:08 am

I haven't tested this yet but here is what I'm doing in case it helps anyone:

In system/library/request.php:

Replace:

Code: Select all

/**
 * 
 * @param	array	$data
 *
 * @return	array
 */
public function clean($data) {
    if (is_array($data)) {
        foreach ($data as $key => $value) {
            unset($data[$key]);

            $data[$this->clean($key)] = $this->clean($value);
        }
    } else {
        $data = htmlspecialchars($data, ENT_COMPAT, 'UTF-8');
    }

    return $data;
}
With:

Code: Select all

/**
 * 
 * @param	array	$data
 * @param 	boolean $isKey Whether the value being cleaned is an array key or value
 *
 * @return	array
 */
public function clean($data, $isKey = false) {
    if (is_array($data)) {
        foreach ($data as $key => $value) {
            unset($data[$key]);

            $data[$this->clean($key, true)] = $this->clean($value);
        }
    } else {

        // Trim value if this isn't an array key
        if (!$isKey) {
            $data = trim($data);
        }

        $data = htmlspecialchars($data, ENT_COMPAT, 'UTF-8');
    }

    return $data;
}
The solutions on this thread seem like the right idea but I don't understand why the trim function is being added as a recursion map when clean($data) is already a recursion function. In theory, putting the trim function in the else statement like I have will mean it is only applied to strings (assuming the data will only ever be an array or a string) so it shouldn't lead to any errors.

Since array keys are also run through this function I have also added an 'isKey' check to ensure whitespaces are only trimmed from the values rather than the keys too.

Newbie

Posts

Joined
Thu Jun 01, 2017 7:12 pm
Who is online

Users browsing this forum: No registered users and 7 guests