\Drupal\rest\Plugin\rest\resource\EntityResourceValidationTrait produces error messages with a trailing newline

Created on 18 September 2019, over 5 years ago
Updated 3 March 2023, almost 2 years ago

Problem/Motivation

\Drupal\rest\Plugin\rest\resource\EntityResourceValidationTrait::validate() loops over any validation violations adding them to textual error message:

      foreach ($violations as $violation) {
        // We strip every HTML from the error message to have a nicer to read
        // message on REST responses.
        $message .= $violation->getPropertyPath() . ': ' . PlainTextOutput::renderFromHtml($violation->getMessage()) . "\n";
      }
      throw new UnprocessableEntityHttpException($message);

However, this leaves a trailing newline character at the end of the message.

Proposed resolution

Trim $message before throwing the exception.

Remaining tasks

* Write simple patch
* Fix several tests that the patch breaks
* Review patch
* Commit patch

User interface changes

A trailing newline will be removed from some error messages (this may break some tests?)

API changes

None.

Data model changes

None.

Release notes snippet

None.

🐛 Bug report
Status

Needs work

Version

10.1

Component
REST 

Last updated 10 days ago

Created by

🇬🇧United Kingdom mcdruid 🇬🇧🇪🇺

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024