For an external link if query parameters are added and if the value is empty, then "=" is included in the url.
when the query param is empty, only the key should be added to the url.

Steps to reproduce

- Add a link field to any content type
- Allow external links for the field.
- Add a new content and fill the link with query parameters
eg: https://www.drupal.org?q=123&test=
- The link will be displayed as https://www.drupal.org?q=123&test= on FE

Issue fork drupal-3100507

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

venugopp created an issue. See original summary.

venugopp’s picture

StatusFileSize
new583 bytes

Here is the fix for the issue.
Replacing !isset with empty

aklalita’s picture

Status: Active » Needs review

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.

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.

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.

kristen pol’s picture

Thanks for the issue and patch. If this is still an issue, it needs a reroll.

kristen pol’s picture

Title: External links cant have empty query parameters » External links cannot have empty query parameters

Fixing title.

kristen pol’s picture

The issue summary needs an update as well.

joshua1234511’s picture

Rerolled the patch for v9.4.0

Tested the Patch and issue as per
- Add a link field to any content type
- Allow external links for the field.
- Add a new content and fill the link with query parameters
eg: https://www.drupal.org?q=123&test=
- The link will be displayed as https://www.drupal.org?q=123&test= on FE
- Apply patch and clear cache
- Revisit the page an the link will be https://www.drupal.org?q=123&test
Before patch
Before
After Patch
After

Updated the issue summary

Status: Needs review » Needs work

The last submitted patch, 11: 3100507_11.patch, failed testing. View results

kristen pol’s picture

Status: Needs work » Needs review

Errors didn't look related so retesting.

Status: Needs review » Needs work

The last submitted patch, 11: 3100507_11.patch, failed testing. View results

joshua1234511’s picture

StatusFileSize
new34.57 KB

Some of the test fails are related to the above change the existing test will also need to be modified as the test are written to have =
Failed Test

On further investigation

(empty($value)) does not handle the 0 case
ie: it will treat 0 as empty
There was 1 failure:

1) Drupal\Tests\system\Functional\Pager\PagerTest::testActiveClass
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'?page=0'
+'?page'

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.

heilop’s picture

StatusFileSize
new606 bytes

The patch #11 Rerolled.

I included an extra validation to avoid treating 0 as empty. I tested for external links and works for internal as well.

joshua1234511’s picture

StatusFileSize
new1.99 KB
new53.95 KB

Investigated the failing test cases.
The above patch applied for all the query parameters irrespective of external or internal links (As per issue reported: only need case for external links)
Eg: internal search links with default key='' case.
Use case
Updated the build query to remove empty query parameters only for external links.

rakhi soni’s picture

Status: Needs work » Needs review
StatusFileSize
new1.99 KB

I have created a patch to fix the 'External links cannot have empty query parameters' issue, Now its working fine on 9.5x version,
Before Patch - url like https://www.drupal.org?q=
After patch - url like https://www.drupal.org?q
kindly review patch,,

kristen pol’s picture

Status: Needs review » Needs work

Still getting failures so back to needs work.

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.

nikolay shapovalov’s picture

Thanks for all you effort, but from my side this doesn't look like bug.
It looks like default behavior.
My suggestion if you want this behavior create custom formatter, or contrib module that implements this.

dcam’s picture

Component: link.module » base system
Status: Needs work » Closed (duplicate)

This is a duplicate of #3040048: Url generator will add '=' after query parameter when value is an empty string which is both older and has more recent work on a fix. Credit has been granted to the people who worked on patches.