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
- Install Drupal
- Create a node
- Edit the path alias to be "0"
- Save
- See the node path is
/node/1rather than/0 - Edit the node
- Confirm the alias field is empty
Proposed resolution
Either:
- Allow "0" to be used as an alias, or
- Throw an error when "0" is entered to indicate it is not allowed
Remaining tasks
- Agree on approach
- Write a patch with tests
- 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:
- Enable the "Path" module.
- Make a node, promoted to front page and having the alias "0".
- 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.
| Comment | File | Size | Author |
|---|---|---|---|
| #37 | 268909-37.patch | 1.69 KB | paulocs |
| #37 | interdiff-33-37.txt | 669 bytes | paulocs |
| #36 | Erro.png | 83.97 KB | paulocs |
| #35 | 268909-after_patch-33.png | 69.26 KB | abhijith s |
| #33 | 268909-33.patch | 1.7 KB | raman.b |
Comments
Comment #1
chx commentedI 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 maybeif (empty($_GET['q']) && !strlen($_GET['q'])instead.Comment #2
Freso commentedThen 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.Comment #3
maartenvg commentedApparently 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.
Comment #4
Anonymous (not verified) commentedDon't we need a test for a path alias of 0 so this doesn't break again?
Comment #5
webchickIndeed, a test would be good.
Comment #6
maartenvg commentedI'm on it.
Comment #7
maartenvg commentedSame 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
Comment #8
Anonymous (not verified) commentedThe last submitted patch failed testing.
Comment #9
maartenvg commentedchasing HEAD.
Comment #10
Anonymous (not verified) commentedThe last submitted patch failed testing.
Comment #11
webchickTemporarily setting back to CNR to re-run testbot.
Comment #12
Anonymous (not verified) commentedThe last submitted patch failed testing.
Comment #13
maartenvg commentedHmmm, 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?
Comment #15
lilou commentedTest failure : #335122: Test clean HEAD after every commit
Comment #17
maartenvg commentedrerolled patch.
Comment #19
Tor Arne Thune commentedIt'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.
Comment #20
Tor Arne Thune commentedComment #21
lyricnz commentedYet another example of empty("0") returning TRUE and causing issues. Update test from #17 (no fix).
Comment #31
pameeela commentedUpdated issue summary to reflect current state.
Comment #33
raman.b commentedI 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.
Comment #35
abhijith s commentedApplied patch #33 .It works fine. Now its showing error message when setting 0 as path alias

Including screenshot
RTBC
Comment #36
paulocsMoving to RTBC. Also added image to confirm.
Tests looks good and well documented.
Comment #37
paulocsAttaching 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.
Comment #42
catchQuite 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!
Comment #43
paulocsVery nice!