Problem/Motivation
I have an entity with a "Link" field. This field is shown in a form with "Link (with attributes)" widget. If I try to create a new entity, or update an existing one, and in this field I add a space at the end, it is not trimmed, and an exception is thrown (BadRequestHttpException: Invalid URI: A URI must not start nor end with ASCII control characters or spaces. in Symfony\Component\HttpKernel\HttpKernel->handle() (line 83 of /vendor/symfony/http-kernel/HttpKernel.php).
It is seemed to be related to this update: https://www.drupal.org/project/drupal/issues/3486195
Steps to reproduce
- Add a "Link" field to a type of entity
- Go to "Manage form display"
- Set widget to "Link (with attributes)"
- Create or update an entity of the previous type
- Go to link field and write a URL, and add a space at the end of the string
- Submit the form
Proposed resolution
Trim empty strings from the Uri property in LinkItem;;preSave