Relative image paths are incorrectly allowed as example image prop values in SDCs and code component example values
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3586958. --> Reported by: [balintbrews](https://www.drupal.org/user/613760) Related to !1034 >>> <h3>Overview</h3> <p>It's currently possible to create a JavaScript component config entity with an invalid example image prop value by using a relative path. An error happens later when the component is being loaded:</p> <pre><pre>Default images for Javascript Components must be a fully-qualified URL with both scheme and host.</pre></pre><p><code>component.yml</code> shape to reproduce the issue:</p> <pre><pre>name: Image URL repro<br>machineName: image_url_repro<br>props:<br>&nbsp; properties:<br>&nbsp;&nbsp;&nbsp; image:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type: object<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $ref: json-schema-definitions://canvas.module/image<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; title: Image<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; examples:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - src: ./hero.jpg<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alt: Example image</pre></pre><h3>Proposed resolution</h3> <p>Move JavaScript specific checks to <code>JavaScriptComponent::checkRequirements()</code> which is called during discovery. This delegates to <code>ComponentMetadataRequirementsChecker::check()</code> for the unified checks, but can also do additional checks for code components - this image src check, the component name check, and then we can add <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-7"><a href="https://www.drupal.org/project/canvas/issues/3587211" title="Status: Closed (fixed)">#3587211: Empty strings are incorrectly allowed as example string prop values in JavaScript component config schema</a></span> here too.</p> <p>#6 mentions that SDCs are affected, but SDCs allow relative images by design, because they are considered relative to the SDC itself. We even have explicit code to handle this in <code>SingleDirectoryComponent::rewriteExampleUrl()</code>. I don't think we can or should break this feature, SDCs can continue to provide local images.</p> <h3>User interface changes</h3> <p>n/a</p> > Related issue: [Issue #3586959](https://www.drupal.org/node/3586959) > Related issue: [Issue #3516602](https://www.drupal.org/node/3516602)
issue