Url::toUriString() doesn't work properly for user input

Created on 28 January 2016, almost 9 years ago
Updated 21 February 2023, almost 2 years ago

Problem/Motivation

Url::toUriString() doesn't work properly for user input. User input is expected to contain a leading slash. The toUriString() method does not render it out.

This issue is a blocker for #2426399: FieldPluginBase::renderAsLink() loses language prefix for tokenized paths β†’ (see comment #47 β†’ on that issue).

Proposed resolution

1. Check user-entered strings for leading slashes in core/lib/Drupal/Core/Url.php.
2. Update necessary tests.

Remaining tasks



3. Review
4. RTBC
5. Commit
6. Update status of #2426399: FieldPluginBase::renderAsLink() loses language prefix for tokenized paths β†’ to Active and comment there about next steps for that issue.

Steps to reproduce and test

1. To reproduce, download the "test-only" patch in comment #2, apply the patch, and run the test. (It should fail.)

For example:

wget https://www.drupal.org/files/issues/2657932-test-only.patch
git apply 2657932-test-only.patch
php ./core/scripts/run-tests.sh --sqlite /tmp/test.sqlite --verbose --non-html --file core/tests/Drupal/Tests/Core/UrlTest.php

2. Un-apply the patch (because the final patch will conflict with it).

For example:

git apply -R 2657932-31.patch

3. Download and apply the latest patch.

For example (using the patch in #31):

wget https://www.drupal.org/files/issues/2022-05-10/2657932-31.patch
git apply 2657932-31.patch

4. Run the tests locally again and it should pass this time.

For example:

php ./core/scripts/run-tests.sh --sqlite /tmp/test.sqlite --verbose --non-html --file core/tests/Drupal/Tests/Core/UrlTest.php

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
RoutingΒ  β†’

Last updated 1 day ago

Created by

πŸ‡ΊπŸ‡ΈUnited States mpdonadio Philadelphia/PA/USA (UTC-5)

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.

  • πŸ‡ΊπŸ‡ΈUnited States tim.plunkett Philadelphia

    Patch still applies against current dev version, leaving at NR

  • Status changed to Needs work almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Maybe I'm testing wrong.

    Applied the patch
    Added a link field to a content type
    Tried inputing "test" without a forward slash thinking it would save with the fix but does not.

Production build 0.71.5 2024