If you don't specify a URL alias on node creation, you get a "The path is already in use" error. This only applies on node 2 and above, presumably because the path "" gets saved on node/1, and is therefore unavailable for nodes 2+. I started noticing this last night after #332333: Add a real API to path.module went in, so I assume it's related.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

peximo’s picture

Status: Needs review » Active
FileSize
752 bytes

In path_node_insert() we need to control not only if is set $node->path but also if this field is not empty.
Otherwise path.module create always a empty path.
The following pacth fix this problem.

peximo’s picture

Status: Active » Needs review
Sivaji_Ganesh_Jojodae’s picture

Status: Active » Needs review
FileSize
1.97 KB

@peximo's patch adds !empty check to hook_node_insert alone. In my opinion it should be added to hook_node_validate and hook_node_update as well. hook_node_validate is where the "The path is already in use." error message is generated and thus prevents from node creation.

onejam’s picture

Testing this patch. I still get an error trying to add an article or blog post.

Error: The path is already in use.

Also noticed, when i manually create the url alias, it accepts spaces in the url. Shouldn't it automatically replace the spaces with dashes instead. should this filed as a separate issue?

stBorchert’s picture

This review is powered by Dreditor.

+++ modules/path/path.module	17 Oct 2009 12:59:00 -0000
@@ -161,7 +161,7 @@ function path_delete($criteria) {
+  if (user_access('create url aliases') || user_access('administer url aliases') && !empty($node->path)) {

Don't use empty because in the (rare) case someone wants to add "0" as alias that would fail.
Use $node->path != '' instead.

Sivaji_Ganesh_Jojodae’s picture

oops.. There was a mistake in my previous patch

if (user_access('create url aliases') || user_access('administer url aliases') && !empty($node->path)) {

should be

if ((user_access('create url aliases') || user_access('administer url aliases')) && !empty($node->path)) {

Attached is a patch which corrects this mistake and replaces empty() with != check.

onejam’s picture

Maybe, i'm doing something wrong but patch failed:

patch -p0 -u < url_alias-606888-4.patch

patching file modules/path/path.module
Hunk #1 FAILED at 161.
Hunk #2 FAILED at 201.
Hunk #3 FAILED at 217.
3 out of 3 hunks FAILED -- saving rejects to file modules/path/path.module.rej

Status: Needs review » Needs work

The last submitted patch failed testing.

peximo’s picture

Status: Needs work » Needs review
FileSize
1.86 KB

Rerolled

stBorchert’s picture

Status: Needs review » Reviewed & tested by the community

Works.

onejam’s picture

Yep, works for me too.

One issue though, when i tried to remove the url alias it wouldn't allow me. i'm able to save but old url alias still remains there. Should it not just default back to the internal url alias (ie, node/2)? I guess this might be a separate issue?

kscheirer’s picture

Status: Reviewed & tested by the community » Needs work

patch works for me.

2 notes:

+++ modules/path/path.module	17 Oct 2009 16:38:32 -0000
@@ -161,7 +161,7 @@ function path_delete($criteria) {
+  if ((user_access('create url aliases') || user_access('administer url aliases')) && ($node->path != '')) {
     if (isset($node->path)) {

Code is excuted only when both if statements are TRUE, they should be combined into 1 statement (and this will make the validate function match insert and update).

This needs to have a test attached. I think this issue is critical enough to go in right away even w/o a test, but there should definitely be some follow up.

mr.york’s picture

The fix patch is on this page: http://drupal.org/node/332333

Sivaji_Ganesh_Jojodae’s picture

Status: Needs work » Fixed

Looks like it is fixed. I don't see any error message or an empty alias in {url_alias} table.

heather’s picture

I have just tested a fresh install - and I don't get a break on node creation.

Where/when did this get fixed?

I'd like to make the error highlight in red, as well as some UI text changes.

Anyone know where this issue was fixed?

Shall we close this?

Status: Fixed » Closed (fixed)

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