pathValidator does not pass internal URIs

Created on 17 October 2022, about 2 years ago
Updated 20 September 2023, about 1 year ago

Problem/Motivation

I get errors like Field %field for %type %label in language %langcode not saved, invalid uri "%uri" for internal URIs like internal:/node/1.

Steps to reproduce

Create content type with link field.
Create content with an external URL like https://drupal.org
Upload it for translation to Lingotek.
Download the translation.
Update the URL to an internal one, e.g. /node/1.
Upload for translation.
Try to download translation.
See the URI remained unchanged.
See watchdog warning.

Proposed resolution

As Url::fromInternalUri() states:

when using a PathValidatorInterface to validate 'internal:' URIs, we must map:

'internal:' (path component is '') to the special '' path
'internal:/' (path component is '/') to the special '' path
'internal:/some-path' (path component is '/some-path') to 'some-path'

We cannot pass in internal URI to it directly and should convert it to a URL first.

Also, PathValidatorInterface::isValid() also checks access of current user to the path which is not needed. It makes sense to use PathValidatorInterface::getUrlIfValidWithoutAccessCheck() method instead.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Needs review

Version

4.1

Component

Code

Created by

🇨🇾Cyprus alex.bukach

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