WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 16 months ago

#42288 new defect (bug)

Validation of custom menu link

Reported by: dvirhazout Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.8.2
Component: Menus Keywords: needs-patch needs-testing
Focuses: javascript Cc:
PR Number:

Description

  1. go to menus page
  2. try to add custom menu link with label only. without a URL.

expected and actual result: validation failed and link cannot be added.

  1. go to menus page
  2. add custom menu link with label and URL: '#'
  3. save menu
  4. edit the custom link from the menu and remove the URL.
  5. click save

expected result: validation failed and menu won't be saved.
actual result: menu saved. no validation.

Attachments (1)

42288.diff (1.2 KB) - added by jukkarau 16 months ago.
Adds URL validation for custom links in customizer

Download all attachments as: .zip

Change History (5)

#1 in reply to: ↑ description ; follow-up: @audrasjb
2 years ago

Replying to dvirhazout:

Hello,
I think that is the desired behavior.
Indeed, a user might need to use an empty anchor (preferably using "#").

For example, this allows a multilevel menu to add some "virtual" (non-clickable) levels that only serve to unfold the child levels.

#2 in reply to: ↑ 1 ; follow-up: @dvirhazout
2 years ago

If that's the case, I can't understand the motive to this validation from the first place.

Replying to audrasjb:

Replying to dvirhazout:

Hello,
I think that is the desired behavior.
Indeed, a user might need to use an empty anchor (preferably using "#").

For example, this allows a multilevel menu to add some "virtual" (non-clickable) levels that only serve to unfold the child levels.

#3 in reply to: ↑ 2 @mukesh27
2 years ago

  • Keywords needs-patch added

@dvirhazout you are right WordPress core team need to add patch for validation or they have to remove validation when anyone add custom menu without link.

Replying to dvirhazout:

If that's the case, I can't understand the motive to this validation from the first place.

Replying to audrasjb:

Replying to dvirhazout:

Hello,
I think that is the desired behavior.
Indeed, a user might need to use an empty anchor (preferably using "#").

For example, this allows a multilevel menu to add some "virtual" (non-clickable) levels that only serve to unfold the child levels.

@jukkarau
16 months ago

Adds URL validation for custom links in customizer

#4 @jukkarau
16 months ago

  • Keywords needs-testing added

Attached a diff, which adds validation for the custom link URLs in the Customizer menus. Using the exact same regex, which is used on the frontend code. The validation now checks the URL format for the submitted strings, and if the URL is empty it invalidates that too. (https://github.com/jukra/wordpress-develop/pull/1)

Note: See TracTickets for help on using tickets.