Problem/Motivation

If you enter "0" as the path alias of a node, the value is allowed and the node is saved, but on editing the alias value is empty and the path /0 does not work.

Steps to reproduce

  1. Install Drupal
  2. Create a node
  3. Edit the path alias to be "0"
  4. Save
  5. See the node path is /node/1 rather than /0
  6. Edit the node
  7. Confirm the alias field is empty

Proposed resolution

Either:

  1. Allow "0" to be used as an alias, or
  2. Throw an error when "0" is entered to indicate it is not allowed

Remaining tasks

  1. Agree on approach
  2. Write a patch with tests
  3. Review

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

Original report by [username]

While playing around with #262774: Code (style) normalisation (using DRUPAL-6), I discovered that if a node has "0" as its path alias, it won't be used when linking to the node.

Steps to reproduce:

  1. Enable the "Path" module.
  2. Make a node, promoted to front page and having the alias "0".
  3. Check "node" and see that other nodes correctly link to their configured alias, except for the one with the alias "0", which'll link to "node/X".

Applies to both 6.x and 7.x. Not tested on 5.x.

Comments

chx’s picture

I thought this was introduced by the infamous kitchen sink but no this dates back to 2003 Sep 30. Caused by if (!empty($_GET["q"])) { in common.inc first then the same code was moved to path.inc. I would try maybe if (empty($_GET['q']) && !strlen($_GET['q']) instead.

Freso’s picture

Then it's likely in 5.x as well, no? :)

Anyway, your suggested change (to drupal_init_path()) doesn't fix this. I also realise I didn't mention in the original issue that going directly to "0" returns the node just fine - "0" is just not used for links.

maartenvg’s picture

Status: Active » Needs review
StatusFileSize
new3.37 KB

Apparently something has changed, because currently the '0' isn't saved at all. And it doesn't matter where you create the path, in the node creation or in admin/build/path, the 0 won't be saved to the database. So in fact, it is already sort of fixed, you can't use 0 as a path. But you don't get a message when you try to set the path to '0', so it's not a good fix.

But I can understand why some people would want a '0' as path, and in fact, it should just work regardless of common use. So I've research the problem and created a patch for it.

This behavior is mainly caused because 0, or '0', is seen as FALSE and as empty. Attached patch introduces the necessary isset()'s and other checks to make sure that 0 is not blocked but the '' (empty string) is.

All path tests run ok, simpletest reports no failures, so it probably doesn't introduce any new problems.

Anonymous’s picture

Don't we need a test for a path alias of 0 so this doesn't break again?

webchick’s picture

Status: Needs review » Needs work

Indeed, a test would be good.

maartenvg’s picture

Assigned: Unassigned » maartenvg

I'm on it.

maartenvg’s picture

Status: Needs work » Needs review
StatusFileSize
new5.3 KB

Same as #3 but with tests.

path.test now tests:
- creating a node with alias '0'
- whether the alias can be accessed
- whether URLs to the node use the alias

Anonymous’s picture

Status: Needs review » Needs work

The last submitted patch failed testing.

maartenvg’s picture

Status: Needs work » Needs review
StatusFileSize
new5.29 KB

chasing HEAD.

Anonymous’s picture

Status: Needs review » Needs work

The last submitted patch failed testing.

webchick’s picture

Status: Needs work » Needs review

Temporarily setting back to CNR to re-run testbot.

Anonymous’s picture

Status: Needs review » Needs work

The last submitted patch failed testing.

maartenvg’s picture

Status: Needs work » Needs review

Hmmm, strange.. on a fresh checkout of HEAD, this patch doesn't fail any tests as reported by http://testing.drupal.org/pifr/file/1/1395.

Can someone confirm?

Status: Needs review » Needs work

The last submitted patch failed testing.

lilou’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch failed testing.

maartenvg’s picture

Status: Needs work » Needs review
StatusFileSize
new5.29 KB

rerolled patch.

Status: Needs review » Needs work

The last submitted patch failed testing.

Tor Arne Thune’s picture

It's still not possible to set 0 as an alias. The alias is accepted and the UI operation displayed as successful, but the change is not made. Can be confusing.

Tor Arne Thune’s picture

Version: 7.x-dev » 8.x-dev
lyricnz’s picture

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

Yet another example of empty("0") returning TRUE and causing issues. Update test from #17 (no fix).

Status: Needs review » Needs work

The last submitted patch, 268909-zero-path-alias.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

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

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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.

pameeela’s picture

Title: Path alias "0" not used for links » "0" can't be used a path alias, but no error is shown
Version: 8.9.x-dev » 9.1.x-dev
Issue summary: View changes
Issue tags: +Bug Smash Initiative

Updated issue summary to reflect current state.

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.

raman.b’s picture

Assigned: maartenvg » Unassigned
Status: Needs work » Needs review
StatusFileSize
new916 bytes
new1.7 KB

I think the error message The alias path has to start with a slash. should be displayed when the user tries to use '0' as path alias.

Here is an updated patch with minimal changes.

The last submitted patch, 33: 268909-33-test-only.patch, failed testing. View results

abhijith s’s picture

StatusFileSize
new69.26 KB

Applied patch #33 .It works fine. Now its showing error message when setting 0 as path alias
Including screenshot
after

RTBC

paulocs’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new83.97 KB

Moving to RTBC. Also added image to confirm.

Tests looks good and well documented.

paulocs’s picture

StatusFileSize
new669 bytes
new1.69 KB

Attaching a new patch because t() should not be called in tests

As this is not a big change, I let the issue status as RTBC.

  • catch committed 29689c2 on 9.2.x
    Issue #268909 by maartenvg, raman.b, paulocs, lyricnz, Abhijith S,...

  • catch committed ee387f3 on 9.1.x
    Issue #268909 by maartenvg, raman.b, paulocs, lyricnz, Abhijith S,...

  • catch committed 42d9665 on 9.0.x
    Issue #268909 by maartenvg, raman.b, paulocs, lyricnz, Abhijith S,...

  • catch committed 2373cb0 on 8.9.x
    Issue #268909 by maartenvg, raman.b, paulocs, lyricnz, Abhijith S,...
catch’s picture

Version: 9.2.x-dev » 8.9.x-dev
Status: Reviewed & tested by the community » Fixed

Quite something to commit a twelve year old bug report for code added 17 years ago.

Committed/pushed to 9.2.x and cherry-picked back through to 8.9.x, thanks!

paulocs’s picture

Very nice!

Status: Fixed » Closed (fixed)

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