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

Created on 18 September 2019, over 4 years ago
Updated 3 March 2023, over 1 year 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 22 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.69.0 2024