Data consistency on request input

The CommonComponent is added to all my apps by default for the last 15+ years. It ensures basic data integrity on request input in regards to emptiness.
This needs to happen in communication layer to ensure this for all other layers. Can be skipped for edge cases using `notrim` config on the component.

if ($this->request->getQuery('key')) {}
if ($this->request->getData('key')) {}

Imagine the behavior change if this was invoked for empty string that is actually just containing whitespace/noise.
The same for model validation rules that rely on not empty string input for the data to be saved to make sense .

Form post Example

Try to pass validation rule notEmpty by adding whitespace (e.g. space) into the input (or before/after a string input).

Notice how the input is trimmed before passing it on to the controller action and validation.

Query String Example

Especially URL input often can contain additional whitespace due to badly formed links.

Normal

'key' => 'Some value'

Value processed will be exactly the same.

Leading and trailing whitespace

'key' => ' Some value '

Notice how the data is trimmed.

Whitespace only (1 space)

['key' => ' ']

Notice how this doesnt trigger the if clause (as it should not).

Disable trimming

Just to show the difference in behavior and data, you can disable the trimming in this demo by adding `notrim=1` to the URL:
Enabled | Disable


Send your feedback or bugreport!