`{type: string, format: uri}` disallows image URLs containing spaces, `uri` data type stores + returns invalid URIs!

Created on 21 August 2024, 3 months ago
Updated 4 September 2024, 2 months ago

Overview

Previously: 🐛 Follow-up for #3461499: figure out why`format: uri` fails + remove erroneous accompanying early return Fixed — that worked around the upstream bug (https://github.com/jsonrainbow/json-schema/issues/685) for randomly generated values for UriItem.

But this problem also occurs in non-test scenarios when:

  1. Follow the set-up steps in CONTRIBUTING.md
  2. Go to /node/add/article
  3. Upload a file containing spaces in the "hero" field

Expected: file uploads.

Actual: crashes, because:

  1. all fields are validated by (it'll restrict the validation errors AFTERWARDS to only the fields being edited, in this case the "hero" field)
  2. which calls ValidComponentTreeConstraintValidator</code, which calls <code>AdapterBase::addInput(), which performs JSON schema validation
  3. since it fails JSON schema validation, AdapterBase throws an exception, which the validator does not catch
  4. ⇒ 500 response instead of validation error that gets filtered away

Proposed resolution

  1. ValidComponentTreeConstraintValidator should catch the exception thrown by AdapterBase
  2. Fix \Drupal\Core\TypedData\Plugin\DataType\Uri because it actually does not store/return a valid URI! See for yourself:
    // How the "uri" data type stores and returns values.
    var_dump(filter_var('public://cat.png', FILTER_VALIDATE_URL));
    var_dump(filter_var('public://cat and dog.png', FILTER_VALIDATE_URL));
    // How the "uri" data type SHOULD store or at least return values.
    var_dump(filter_var('public://cat%20and%20dog.png', FILTER_VALIDATE_URL));
    

    prints

    string(16) "public://cat.png"
    bool(false)
    string(28) "public://cat%20and%20dog.png"
    

User interface changes

None.

🐛 Bug report
Status

Fixed

Component

Page builder

Created by

🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024