Problem/Motivation

When adding a node or taxonomy term and the user enters only spaces in "Url Alias" path_form_element_validate executes unnecessary db_select query to check if the alias has been used. path_node_insert, path_node_update, path_taxonomy_term_insert, and path_taxonomy_term_update all trim the $path['alias'] before they check to see if it is empty therefore a spaces only alias will never be saved.

Proposed resolution

Trim the submitted URL alias before checking to see if it is empty. This will eliminate a potential unnecessary db_select execution.

Change

if (!empty($form_state['values']['path']['alias'])) {
    // Trim the submitted value.
    $alias = trim($form_state['values']['path']['alias']);

to

// Trim the submitted value.
  $alias = trim($form_state['values']['path']['alias']);
  if (!empty($alias)) {

I don't know if this is too much of an "corner case" to worry about.
The issue is the same in D7 and D8.
Patch forth coming....

Original report by tedbow

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tedbow’s picture

Status: Active » Needs review
FileSize
891 bytes

Patch attached

tamanna-freelancer’s picture

Status: Needs review » Reviewed & tested by the community

I have reviewed this patch,it works fine.

tedbow’s picture

Great!

tedbow’s picture

shoud this be backported to D7?

xjm’s picture

Issue tags: +Needs backport to D7

Yep. And I thought about it, and I don't think there's really a way nor a reason to test this. I also tested manually just to make sure we don't actually save a path of empty spaces.

(Cue either Floyd or Queen).

catch’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Makes sense, we can't test the presence of the extra query or not, so committed/pushed to 8.x.

Albert Volkman’s picture

Status: Patch (to be ported) » Needs review
FileSize
871 bytes

D7 backport.

xjm’s picture

Status: Needs review » Reviewed & tested by the community

Looks fine for backport as well.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Nice catch! Committed and pushed to 7.x. Thanks!

Automatically closed -- issue fixed for 2 weeks with no activity.