Make WordPress Core

Opened 10 months ago

Last modified 2 months ago

#60916 assigned defect (bug)

Menu link validation

Reported by: nikitasolanki1812's profile nikitasolanki1812 Owned by: rcreators's profile rcreators
Milestone: 6.8 Priority: normal
Severity: normal Version:
Component: Menus Keywords: has-patch changes-requested
Focuses: javascript, administration Cc:

Description

When creating a custom menu link and failing to enter a URL, a validation display should appear.

https://drive.google.com/file/d/1lZ5MkEVrRNRj3Msql5BubWy-jPpP1d13/view

I added a custom link to the menu list, and when I remove the URL and save the menu, the validation does not display.

https://drive.google.com/file/d/1F0kSf0Vgl-bTowlKNg8vYciUNsSeV7Kb/view

Attachments (3)

60916.diff (4.3 KB) - added by akrocks 10 months ago.
Created patch adding URL validation to Custom Links menu section.
60916.1.diff (5.6 KB) - added by akrocks 10 months ago.
Added commit to replace spaces with tabs.
60916.2.diff (8.2 KB) - added by akrocks 8 months ago.
Converts const to var + Removes extra lines.

Download all attachments as: .zip

Change History (20)

This ticket was mentioned in Slack in #accessibility by joedolson. View the logs.


10 months ago

#2 @joedolson
10 months ago

  • Focuses accessibility removed
  • Milestone changed from Awaiting Review to 6.6
  • Owner set to rcreators
  • Status changed from new to assigned
  • Version 6.5 deleted

This isn't in itself an accessibility issue; consistency between the two fields doesn't impact different users differently.

This does call attention to the validation itself, however, which is not accessible, and I'll open a separate issue for that.

#3 @sabernhardt
10 months ago

  • Component changed from General to Menus
  • Keywords needs-patch added; changes-requested removed

@akrocks
10 months ago

Created patch adding URL validation to Custom Links menu section.

@akrocks
10 months ago

Added commit to replace spaces with tabs.

This ticket was mentioned in PR #6389 on WordPress/wordpress-develop by @akrocks.


10 months ago
#4

  • Keywords has-patch added; needs-patch removed

Trac ticket: https://core.trac.wordpress.org/ticket/60916

## Description

  • This PR adds URL validation to the Custom Link menu items.

## Steps to reproduce Bug

  • If we try adding Custom Link with an empty URL in the Menu, We get a validation error & are not able to add Custom Link.

https://github.com/Pathan-Amaankhan/wordpress-develop/assets/63953699/80590807-8df8-45d6-9261-2ab8535e0fb3

  • But if we try the same after adding Custom Link to the Menu, we don't get the validation error & can add Custom Link with an empty URL. This breaches the consistency.

https://github.com/Pathan-Amaankhan/wordpress-develop/assets/63953699/e36f3b2b-09be-4db4-9baa-81346756f2e8

## Expected behaviour

  • A validation error should be shown if we add Custom Link with an empty URL.

## Screenshots/Screencasts

#### Before

  • Able to save Custom Link with an empty URL.

https://github.com/Pathan-Amaankhan/wordpress-develop/assets/63953699/e36f3b2b-09be-4db4-9baa-81346756f2e8

#### After

  • A validation error is displayed if we try to save Custom Link with an empty URL.

https://github.com/Pathan-Amaankhan/wordpress-develop/assets/63953699/11e32112-096a-46eb-afee-efb134a5dd8d

---

This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@rcreators commented on PR #6389:


9 months ago
#5

@Pathan-Amaankhan Can you make the changes as per suggestions? That will be great.

#6 @rcreators
9 months ago

  • Keywords changes-requested added

@akrocks
8 months ago

Converts const to var + Removes extra lines.

@akrocks commented on PR #6389:


8 months ago
#7

Hi @Rcreators 👋,
I have updated the PR, as per the suggested changes.
Can you please re-review the PR.

This ticket was mentioned in Slack in #core by oglekler. View the logs.


8 months ago

#9 @ironprogrammer
7 months ago

Thank you, everyone, for keeping on with this ticket! In my testing I found a regression and a couple of things that should be addressed (possibly in another ticket).

Test Report

Patch tested: https://github.com/WordPress/wordpress-develop/pull/6389

Steps to Reproduce or Test

  1. Setup: With a classic theme active that supports menus, set up a new menu and add links using Add menu items > Custom Links:
    1. Add link with valid URL. Should be added to menu.
    2. Add link with hash (e.g. #content). Should be added to menu.
    3. Add link with random text that isn't a URL. Should be added to menu, prepended by http://.
    4. Try using a space for URL, confirm validation occurs. Cannot add.
    5. Save menu. Should include the three items successfully added above.
  2. Test using Menu structure to modify links directly:
    1. Replace URL with a space in one of the links.
    2. Save menu and observe modified link's URL.
    3. Save menu again and observe modified link's URL (expect this should be unchanged). Make note of this link and do not modify it before applying patch.
    4. [Optional] Add valid URL, save, remove URL, save. Should be same as above.

Expected Results

When reproducing the bug:

  • ❌ Links with blank or unset (http:// or https://) URLs are not validated and can be saved.

When testing a patch to validate it works as expected:

  • ✅ Links with blank or unset (http:// or https://) URLs are validated, indicating an error.
  • ✅ Links with validation errors prevent saving the menu.

Environment

  • Hardware: MacBook Pro Apple M1 Pro
  • OS: macOS 14.5
  • Browser: Safari 17.5
  • Server: nginx/1.27.0
  • PHP: 8.2.20
  • MySQL: 8.0.27
  • WordPress: 6.6-alpha-57778-src
  • Theme: twentytwentyone v2.2

Actual Results

  • Apply patch and run npm run build:dev.
  • Refresh page and make sure the modified blank URL link from above exists.
  • Using Menu structure to modify links directly:
    • ✅ Expand the link with a blank URL, observe that field displays placeholder (https://).
    • ❌ Observe that field does NOT reflect validation.
    • ❌ Save menu without making any changes. Link with blank URL disappears. (Regression: Should not delete links with invalid URL, as they could be unintentionally deleted after patch or WP upgrade.)
    • ✅ Delete the URL from one of the other links, confirm validation occurs. Cannot save.
    • ⚠️ Enter a space in the URL field, confirm NO validation occurs. (Consistent with before patch; but does not match validation of Custom Links adder.)
    • Save menu. Items should include link just modified.
    • ⚠️ Expand blank URL link, observe space has been removed, showing placeholder text, confirm NO validation occurs. (Consistent with before patch.)
    • ❌ Save menu. Blank URL link disappears. (Regression like above: Should not delete links with invalid URL.)
    • ✅ Delete URL from remaining link, confirm validation occurs.
    • ✅ Try entering http:// or https://, confirm validation occurs.

Supplemental Artifacts

#10 @audrasjb
7 months ago

  • Milestone changed from 6.6 to 6.7

Given 6.6 RC1 is coming in 3 days and as regressions were found with the current patch, I'm moving this ticket to milestone 6.7. The ticket is pretty close to its resolution, but the regression have to be addressed before it ships, especially when we are so close to RC1.

This ticket was mentioned in Slack in #core-test by ankit-k-gupta. View the logs.


5 months ago

#12 @Ankit K Gupta
5 months ago

Thanks @akrocks for the PR. This ticket was discussed in Test Scrub session this week. Would you mind updating/addressing the issues identified in the testing here https://core.trac.wordpress.org/ticket/60916#comment:9

This ticket was mentioned in Slack in #core by chaion07. View the logs.


4 months ago

#14 @chaion07
4 months ago

Thanks @nikitasolanki1812 for reporting this. We reviewed this Ticket during a recent bug-scrub session. Based on the feedback received we would like to request the following:

  1. Seconding with Ankit for an update on the issue (regression) found during the test conducted by Brian
  2. Possible a patch
  3. Information on the Ticket that Brian suggested to open apart from this one which should address the issues.

Thanks you.

Props to @ironprogrammer, @ankit-k-gupta and @pratiklondhe

Cheers!

This ticket was mentioned in Slack in #core by stoyangeorgiev. View the logs.


4 months ago

#16 @stoyangeorgiev
4 months ago

  • Milestone changed from 6.7 to 6.8

This one was discussed during a bug-scrub. With Beta 2 right around the corner, will move this one to 6.8

This ticket was mentioned in PR #7869 on WordPress/wordpress-develop by @rinkalpagdar.


2 months ago
#17

Trac ticket: https://core.trac.wordpress.org/ticket/60916

### Description
_

  • This PR adds URL validation to the Custom Link menu items.

### Expected behaviour
_

  • A validation error should be shown if we add Custom Link with an empty URL.

### Screenshots/Screencasts
_

https://github.com/user-attachments/assets/82099356-b451-404a-a414-3f9c0377bb72

Note: See TracTickets for help on using tickets.