Problem/Motivation

Currently, In default link field we have URL and Link text.
URL field accepts multiple URLs, which leads to creating broken URL in the node view page.

e.g. I can add 2 urls same time https://www.google.com, https://www.google.in
and in node view, it comes as https://www.google.com%2C%20https//www.google.in

See attached images:
Multiple urls
Multiple urls

Steps to reproduce

  1. Add a Link Field to a content type allow one value
  2. Add a node of that content type and in the Link field add two Urls separated by a comma, for example, https://www.google.com, https://www.google.in.
  3. Save - notice no errors

Proposed resolution

Validate the field using UrlElement::validateUrl()

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-2935307

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

chintan4u created an issue. See original summary.

n.kishorekumar’s picture

Status: Active » Needs review
StatusFileSize
new67.38 KB

@chintan4u
i think the way you added multiple url is not right

For adding multiple URLs,
while creating field in the content type we should select unlimited values in the field settings

chintan4u’s picture

I know that :)

My point is we need to validate the URL field for Comma or Space so only one URL value should be accepted and when a user just copy-pastes multiple URLs in the same text-box it should throw an error.
So a user will understand for multiple URLs he needs to add multiple URL fields.

Currently, It accepts the multiple URLs without any warning or error, Which leads to broken URL.

cilefen’s picture

Title: Link field should accept one URL at a time » Link field doesn't sufficiently validate input: it accepts multiple URLs, for example
Status: Needs review » Active
Issue tags: -link
chintan4u’s picture

Assigned: Unassigned » chintan4u
chintan4u’s picture

Status: Active » Needs review
StatusFileSize
new772 bytes

Validation patch added.

Status: Needs review » Needs work
chintan4u’s picture

Assigned: chintan4u » Unassigned
sanduhrs’s picture

Title: Link field doesn't sufficiently validate input: it accepts multiple URLs, for example » Link field doesn't sufficiently validate input
Version: 8.4.x-dev » 8.8.x-dev
Priority: Normal » Major
Status: Needs work » Needs review
StatusFileSize
new1.05 KB

The LinkWidget apparently overrides '#element_validate' of the url form element defined in \Drupal\Core\Render\Element\Url.

'#element_validate' => [[get_called_class(), 'validateUriElement']],

The attached patch readds it, please review.

Status: Needs review » Needs work

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

esmoves’s picture

Issue tags: +Amsterdam2019

Hi, I'm at the contributionday and looking to do Major issue triage on this issue.

mradcliffe’s picture

@esmoves, @ChrisDarke and I are learning #2474049: [meta] Major issue triage together.

esmoves’s picture

Issue tags: +Triaged for D8 major current state

Confirmed Priority Major for this issue.

  1. Reproduced this issue using 8.9.x, clean installation.
  2. Added a Link Field, allowed unlimited number of values.
  3. Added a basic page with two url in the Link Field (https://www.google.com, https://www.google.in), added a Link text.
  4. When saving, no errors are shown.
  5. The link comes out as text link

No duplicate issues found.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

gmercer’s picture

We found a small issue related to patch #9 regarding fields that support internal links. They were incorrectly being marked as invalid during validation. This patch expands on what was done in patch #9, but accounts for internal links when setting '#element_validate'.

logickal’s picture

Status: Needs work » Needs review
StatusFileSize
new3.2 KB

We ran into this recently with a client using fields configured to accept both internal and external links. A user entered a malformed URL and Drupal accepted it with no issues, breaking pages on the site. Found this issue and tried these patches but while they seem to be headed in the right direction, didn't actually approach the issue we found.

Here is a first attempt to get validation working for internal/external links in the same field, but could obviously be improved.

Status: Needs review » Needs work

The last submitted patch, 17: link_field_validation-2935307-17.patch, failed testing. View results

logickal’s picture

StatusFileSize
new3.7 KB

Found that the previous approach was failing to save internal links entered with a leading slash, which should also work in this use case. Leaving this as Needs Work since the same tests will likely fail. I will try to revisit this soon with test work.

ridhimaabrol24’s picture

Status: Needs work » Needs review
StatusFileSize
new3.33 KB

Patch #19 failed to apply. Re rolling the patch for 9.1.x

ridhimaabrol24’s picture

StatusFileSize
new3.41 KB
new939 bytes

Fixing PHP lint error

quietone’s picture

Came here to see if this is the same as #2652236: Insufficient link validation for external URLs in link widget and appears it is not. The other issue is about validating the URL but this is that the URL itself get munged. Reading the issue (the IS and #14) suggests that this only happens for multi value fields. Is that true?

It would help if the IS was updated to clarify when this problem happens and to also include steps to reproduce. And, of course, this will need tests so adding tag for that.

To assist reviewer remember when rerolling patches to add an interdiff, or a diff if the interdiff fails. Thanks!

Status: Needs review » Needs work

The last submitted patch, 21: 2935307-21.patch, failed testing. View results

logickal’s picture

I agree that this needs some further issue replication testing. I'm trying to take a couple of steps back and evaluated the various URL validation issues and try to get some clarity around this. What it DOES look like is that it is specifically impacting fields configured to support both Internal and External URLs.

I would also add a caveat to my submitted patches - not only has upstream changed ahead of where I was working (thanks @ridhimaabrol24 for the re-roll) but we found that my patches then broke submission of internal links prefixed with a single slash such as /node/add, so this obviously needs a different approach.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

quietone’s picture

Adding this to a meta about link and url validation. #3188110: [Meta] Improve URL validation. Not making it a child at this time.

quietone’s picture

Issue summary: View changes

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

xjm’s picture

Issue tags: -Triaged for D8 major current state, -needs test +Needs tests

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

dcam made their first commit to this issue’s fork.

dcam’s picture

Status: Needs work » Closed (duplicate)

I did additional testing.

If the URL input accepts a second URL, then I think the natural next step is to wonder if it accepts any input after the URL. It does! Try entering any garbage text after a URL. It can be saved with no problem. So this issue isn't specifically about a "second URL."

Then it follows that one should wonder "How much invalid input does this actually accept?" It turns out that you can enter anything after the URL scheme and it will pass validation.

All this means that @quietone's instincts were initially correct and this issue is a duplicate of #2652236: Insufficient link validation for external URLs in link widget.

dcam credited chrisdarke.

dcam’s picture

Granting credit to the major issue triage contributors from Amsterdam 2019.