Not all URIs are URLs, but UriWidget won't accept non-URL URIs

Created on 5 December 2020, about 4 years ago
Updated 29 February 2024, 10 months ago

Problem/Motivation

Meta issue: Drupal's nomenclature and code blurs the line between URIs and URLs in such a way that pretty much always assumes all URIs are URLs.

Example: The UriWidget provides a field widget for the uri entity field type. While the docblock on the field type references RFC 2616, this is actually the HTTP/1.1 spec; the applicable spec for URIs (of which URLs are a specific type) is RFC 3986.

Or, consider the case of simple_oauth (I'm the junior maintainer now) which adds a uri field on to the consumer entity for purposes of registering a redirect_uri value for OAuth 2.0. This value is often - but not always - a URL, but in the case of apps might look like my.app:/oauthredirect (a valid URI resolved by the phone's OS/middleware.)

In core, the core Link module has a uri property but stores only URLs and this makes sense in context.

(There are some internal URIs (e.g., internal://) that can be converted to URLs, and in this case the nomenclature is correct. E.g., Url::fromUri())

Proposed resolution

Clearly the 99% case here is that in practice URL == URI for most all users. However, this amounts to a bit of DX false advertising when a developer might reasonably assume that UriWidget accepts URIs. Consider however the url form element calls UrlHelper::isValid() for validation, which checks only a subset of RFC 3986. (It actually also broadens the validation to restirct to only http/https/feed.)

(It's worth noting this is some of the oldest code in Drupal; I traced the genesis of the inclusion of feed as a scheme to Dries in 2010!)

URLs and URL generation are important to web sites and this is definitely one area in which we have to consider BC. That said, it would also be good/appropriate for Drupal to treat URLs and URIs as per the spec and not create unnecessary developer WTF conditions when you really, actually want a URI.

There's no particular reason why developers who actually want to store a URI in a uri field can't change the element validation callbacks for the form element in an alter. I propose adding a validation function (most of the examples around the web speak to parsing, which is not necessary here) and also cleaning up a few of the more confusing docblocks that intermix URL and URI terminology.

Remaining tasks

Decide if this is a bigger issue we want to tackle (probably not/maybe only for Drupal 10?) and hone in on the DX components that are actionable and don't break BC.

User interface changes

None

API changes

None unless we want to tackle this e.g. by deprecating/renaming to be more consistent in Drupal 10.

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Field 

Last updated about 22 hours ago

Created by

🇺🇸United States bradjones1 Digital Nomad Life

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Merge request !101Update plugin docblocks → (Open) created by bradjones1
  • 🇺🇸United States smustgrave

    Can the MR be updated for 10.1 please

    As far as your question in #11 maybe the #contribute channel could give some feedback? Or #bugsmash?

  • First commit to issue fork.
  • 🇺🇸United States bradjones1 Digital Nomad Life

    @sourabh_jain_419 can you explain what you're doing?

  • 🇮🇳India sourabhjain

    @bradjones I have rebase the branch.

  • 🇺🇸United States smustgrave

    FYI rebasing the branch but not adding anything does not get credit.

  • 🇺🇸United States bradjones1 Digital Nomad Life

    Also you rebased on 9.2 which is not helpful here.

  • 🇺🇸United States bradjones1 Digital Nomad Life

    This is also pertinent to 🐛 `LinkCollection::validKey()` does not properly validate RFC 8288 link relation types Active which also needs "true" URI validation.

  • 🇩🇪Germany tstoeckler Essen, Germany

    Thanks for the patch! Didn't review it, but can verify it works. Hit a bug with Diff module with this, though, that it fails to diff non-URL URIs that are created with this patch.

    Created a little diff plugin for that, attaching that in case this helps anyone. Once this lands, will open an issue for that over in Diff module. To be placed in src/Plugin/diff/Field for you custom module (removing the _.txt extension) and then just replace the module name in the namespace.

  • Pipeline finished with Success
    9 months ago
    Total: 186s
    #138542
  • Pipeline finished with Success
    9 months ago
    Total: 216s
    #138554
  • Pipeline finished with Failed
    9 months ago
    #142716
  • Pipeline finished with Canceled
    9 months ago
    Total: 61s
    #142723
  • Pipeline finished with Failed
    9 months ago
    Total: 416s
    #142729
  • Pipeline finished with Failed
    9 months ago
    Total: 412s
    #142749
  • Pipeline finished with Canceled
    9 months ago
    Total: 32s
    #142753
  • Pipeline finished with Failed
    9 months ago
    Total: 225s
    #142755
  • Pipeline finished with Success
    9 months ago
    Total: 417s
    #142758
  • Pipeline finished with Failed
    7 months ago
    Total: 213s
    #171880
  • Pipeline finished with Success
    5 months ago
    Total: 232s
    #225666
  • Pipeline finished with Success
    5 months ago
    Total: 323s
    #225709
  • Pipeline finished with Failed
    5 months ago
    Total: 287s
    #225819
  • Pipeline finished with Success
    5 months ago
    Total: 263s
    #225832
  • Pipeline finished with Success
    5 months ago
    Total: 316s
    #225839
  • Pipeline finished with Success
    5 months ago
    Total: 291s
    #225883
  • Pipeline finished with Success
    5 months ago
    Total: 329s
    #225903
  • Pipeline finished with Success
    5 months ago
    Total: 168s
    #227906
  • Pipeline finished with Success
    5 months ago
    Total: 177s
    #227954
  • Pipeline finished with Skipped
    5 months ago
    #227969
  • Pipeline finished with Success
    5 months ago
    Total: 247s
    #236414
  • Pipeline finished with Success
    5 months ago
    Total: 239s
    #236432
  • Pipeline finished with Success
    5 months ago
    Total: 141s
    #237483
  • Pipeline finished with Success
    5 months ago
    Total: 194s
    #237496
  • Pipeline finished with Success
    5 months ago
    Total: 138s
    #237511
  • Pipeline finished with Success
    5 months ago
    Total: 154s
    #237534
  • Pipeline finished with Success
    5 months ago
    Total: 151s
    #239157
  • Pipeline finished with Success
    5 months ago
    Total: 257s
    #245657
  • Pipeline finished with Success
    4 months ago
    Total: 140s
    #252475
  • Pipeline finished with Success
    4 months ago
    Total: 146s
    #252476
  • Pipeline finished with Success
    4 months ago
    Total: 181s
    #252487
  • Pipeline finished with Success
    4 months ago
    Total: 169s
    #252489
  • Pipeline finished with Success
    4 months ago
    #252494
  • Pipeline finished with Success
    4 months ago
    #252558
  • Pipeline finished with Success
    4 months ago
    Total: 296s
    #253492
  • Pipeline finished with Success
    4 months ago
    Total: 160s
    #253508
  • Pipeline finished with Success
    4 months ago
    Total: 182s
    #269349
  • Pipeline finished with Success
    4 months ago
    #269651
  • Pipeline finished with Success
    3 months ago
    Total: 146s
    #285876
  • Pipeline finished with Success
    3 months ago
    Total: 131s
    #286462
  • Pipeline finished with Success
    3 months ago
    Total: 250s
    #286484
  • Pipeline finished with Success
    3 months ago
    Total: 134s
    #286491
  • Pipeline finished with Success
    3 months ago
    Total: 135s
    #286508
  • Pipeline finished with Success
    3 months ago
    Total: 131s
    #286509
  • Pipeline finished with Failed
    3 months ago
    Total: 168s
    #288558
  • Pipeline finished with Success
    3 months ago
    Total: 161s
    #289539
  • Pipeline finished with Failed
    3 months ago
    Total: 352s
    #289546
  • Pipeline finished with Success
    3 months ago
    Total: 175s
    #289589
  • Pipeline finished with Success
    3 months ago
    Total: 156s
    #289642
  • Pipeline finished with Success
    3 months ago
    Total: 154s
    #290189
  • Pipeline finished with Failed
    3 months ago
    Total: 213s
    #290526
  • Pipeline finished with Success
    3 months ago
    Total: 167s
    #290530
  • Pipeline finished with Success
    3 months ago
    Total: 153s
    #291095
  • Pipeline finished with Success
    3 months ago
    Total: 153s
    #291120
  • Pipeline finished with Success
    3 months ago
    Total: 151s
    #291121
  • Pipeline finished with Failed
    3 months ago
    Total: 188s
    #291608
  • Pipeline finished with Success
    3 months ago
    Total: 163s
    #292484
  • Pipeline finished with Success
    3 months ago
    Total: 157s
    #292489
  • Pipeline finished with Success
    3 months ago
    Total: 242s
    #292505
  • Pipeline finished with Success
    3 months ago
    Total: 691s
    #293218
  • Pipeline finished with Success
    3 months ago
    Total: 213s
    #293225
  • Pipeline finished with Skipped
    3 months ago
    #296328
  • Pipeline finished with Success
    2 months ago
    Total: 129s
    #303801
  • Pipeline finished with Failed
    2 months ago
    Total: 2272973s
    #288767
  • Pipeline finished with Success
    2 months ago
    Total: 212s
    #312587
  • Pipeline finished with Failed
    2 months ago
    Total: 230s
    #314015
  • Pipeline finished with Failed
    2 months ago
    Total: 248s
    #314237
  • Pipeline finished with Failed
    2 months ago
    Total: 241s
    #315845
  • Pipeline finished with Failed
    2 months ago
    Total: 247s
    #315852
  • Pipeline finished with Success
    2 months ago
    Total: 260s
    #315944
  • Pipeline finished with Failed
    2 months ago
    Total: 264s
    #316274
  • Pipeline finished with Success
    2 months ago
    Total: 191s
    #316314
  • Pipeline finished with Failed
    2 months ago
    Total: 60s
    #317249
  • Pipeline finished with Failed
    2 months ago
    Total: 191s
    #317258
  • Pipeline finished with Success
    about 2 months ago
    #318606
  • Pipeline finished with Success
    about 2 months ago
    #318609
  • Pipeline finished with Success
    about 2 months ago
    #318622
  • Pipeline finished with Success
    about 2 months ago
    #318627
  • Pipeline finished with Success
    about 2 months ago
    #318635
  • Pipeline finished with Success
    about 2 months ago
    Total: 175s
    #325186
  • Pipeline finished with Skipped
    about 2 months ago
    #326228
  • Pipeline finished with Success
    about 2 months ago
    Total: 180s
    #326642
  • Pipeline finished with Failed
    18 days ago
    Total: 389s
    #358410
  • Pipeline finished with Success
    4 days ago
    Total: 339s
    #372730
  • Pipeline finished with Success
    4 days ago
    Total: 345s
    #372740
Production build 0.71.5 2024