Problem/Motivation
Discovered at #2930028-14: Comprehensive JSON API integration test coverage phase 1: for every entity type, individual resources only:
1) Drupal\Tests\jsonapi\Functional\NodeTest::testPostIndividual Failed asserting that two strings are identical. --- Expected +++ Actual @@ @@ -{"errors":[{"title":"Unprocessable Entity","status":422,"detail":"Unprocessable Entity: validation failed.\ntitle: Title: this field cannot hold more than 1 values.\n","links":{"info":"http:\/\/www.w3.org\/Protocols\/rfc2616\/rfc2616-sec10.html"},"code":0}]} +{"errors":[{"title":"Unprocessable Entity","status":422,"detail":"title: \u003Cem class=\u0022placeholder\u0022\u003ETitle\u003C\/em\u003E: this field cannot hold more than 1 values.","code":0,"source":{"pointer":"\/data\/attributes\/title"}}]}Hurray, that is the error we need! It just is formatted in a different way. That should be easy enough to fix. Continuing tomorrow :)
The root cause? \Drupal\jsonapi\Normalizer\UnprocessableHttpEntityExceptionNormalizer::buildErrorObjects() simply passes on the return value from \Symfony\Component\Validator\ConstraintViolation::getMessage(), which is for Drupal entity/field validation returning HTML. Hence the JSON-encoded <em class="placeholder">Title[…] message. Which is obviously less than ideal.
Proposed resolution
Almost exactly a year ago, this was fixed in core REST, in #2835683: Remove HTML from EntityResource validation 422 exception message. Apply the same fix: convert to plain text.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 2934370-2.patch | 2.29 KB | wim leers |
Comments
Comment #2
wim leersTest coverage is being added in #2930028: Comprehensive JSON API integration test coverage phase 1: for every entity type, individual resources only.
Comment #3
wim leersGreen!
Comment #5
wim leers