The "list terms" item at admin/structure/taxonomy uses the vocabulary machine name for the path, but this causes a user to be directed to the taxonomy overview or add pages if the machine name and default menu arguments are the same.

To recreate:

1. Create a vocabulary named "List", allowing the machine name to default to "list".
2. Click the the "list terms" item at admin/structure/taxonomy.

Instead of being taken to the list terms page for the "list" vocabulary, you will stay on the overview page which is the default local task.

Likewise, creating a vocabulary with the machine name 'add', will take you to the add vocabulary page when the "list terms" path is accessed.

Adding "list" as a fourth argument in the path will display the correct page, but this breaks down on MENU_DEFAULT_LOCAL_TASK generated tabs (such as on the vocabulary edit page) .

The easy option is to disallow conflicting machine-names, which prevents having to change paths and menu items in the taxonomy module. I've included a patch that disallows "add" and "list" as machine-names for new vocabularies, though fixing the underlying issue would probably be a better approach if anyone has any input on how that might be accomplished.

Comments

scott falconer’s picture

StatusFileSize
new788 bytes

Attaching the patch.

jhodgdon’s picture

We need this.... subscribe

jhodgdon’s picture

Priority: Normal » Critical

ksenzee says anything you can bork through the UI is critical.

bleen’s picture

+++ modules/taxonomy/taxonomy.adminNEW.inc	2010-07-01 17:10:42.000000000 -0700
@@ -203,7 +203,11 @@ function taxonomy_form_vocabulary_valida
+    // Do not allow machine names to conflict with taxonomy path arguments.

based on this logic shouldn't we disallow "view" "edit" "feed" and (I think) "delete" also? I haven't tested this...

Powered by Dreditor.

bjaspan’s picture

re #3: I think the world of Katherine but I disagree with her on this point. "Anything you can bork through the UI is critical" is not a sensible rule. Is Drupal really useless unless this is fixed? It sounds to me like this can be addressed by saying "don't do that!" and then can be fixed post-7.0. So I suggest marking this normal priority.

http://acquia.com/drupal-7-get-real-get-dirty-get-it-done

pwolanin’s picture

Priority: Critical » Major

Look - this kind of bug is why in places I changed the callback paths for things like managing content type and menus - without that, you have to create a path black list, which is always going to fail in some cases and is really a half-assed solution.

so - 2 possible solutions:

1) change the paths for the /add, etc

2) blacklist (as per the patch above).

jhodgdon’s picture

Someone already (unwisely) must have decided on these current paths in D7, because they are not the same in D6. I'm sure that changing the paths, although it's the right thing to do, would break all kinds of things by now. Sigh.

The blacklist idea is a total hack though.

Other places in core where there are menu router items that have this potential problem (i.e. machine names being used in router paths that could conflict with other paths):
- system_menu: 'admin/config/regional/date-time/types/%/delete' -- the % for type here is a machine name, and there is also 'admin/config/regional/date-time/types/add'
- shortcut_menu: 'admin/config/user-interface/shortcut/%shortcut_set' -- this is a shortcut set name, and there is also 'admin/config/user-interface/shortcut/add-set' and several with ../shortcut/link/* etc.

I personally think we should fix the paths, although it will be painful at this point.

pwolanin’s picture

StatusFileSize
new7.49 KB

Changing paths is not that painful - needs to be done asap.

pwolanin’s picture

StatusFileSize
new0 bytes

Fixed the tests.

pwolanin’s picture

StatusFileSize
new11.54 KB

oops - bad diff

Status: Needs review » Needs work

The last submitted patch, 843162-taxonomy-vocab-paths-10.patch, failed testing.

jhodgdon’s picture

What about the other spots with the same problem in #7?

scott falconer’s picture

StatusFileSize
new13.76 KB

Here's a patch with updated tests for the path change.

scott falconer’s picture

Status: Needs work » Needs review

Updating status to needs review.

Status: Needs review » Needs work

The last submitted patch, 843162-taxonomy-vocab-paths-13.patch, failed testing.

jhodgdon’s picture

Looks like there are still 4 tests failing due to bad paths.

Also, the other spots mentioned in #7 have not been addressed...

scott falconer’s picture

Status: Needs work » Needs review
StatusFileSize
new16.59 KB

Included patch changes the path change from taxonomy-vocabulary to taxonomy/vocabulary. This is more in line with how content types work, keeps the breadcrumbs intact, and fixes the underlying "List" and "Add" name conflict. In a few places, references to argument 3 needed to be changed to 4. I could see this possibly causing some problems with contrib. modules that look to the path arguments to load the vocabulary name, but it should be an easy fix in those cases.

As per the questions in #7, I've checked the paths:

- system_menu: 'admin/config/regional/date-time/types/%/delete' -- the % for type here is a machine name, and there is also 'admin/config/regional/date-time/types/add'

Tested with type names 'add' and 'delete'. No issues.

- shortcut_menu: 'admin/config/user-interface/shortcut/%shortcut_set' -- this is a shortcut set name, and there is also 'admin/config/user-interface/shortcut/add-set' and several with ../shortcut/link/* etc.

Tested with type names 'add-set', 'add' and 'list'. No issues.

A few other places like 'admin/structure/types' use machine names in paths without issue, but it might be a good idea to write a general test that checks path arguments as machine names just to be sure.

jhodgdon’s picture

Thanks for testing...
- Agreed on the date-time paths -- I couldn't make it break either.
- On the shortcut sets, it appears that the machine name of shortcut sets is defined by the shortcut module to be shortcut-set-1, shortcut-set-2, etc. So the name you choose for the shortcut set cannot affect the path adversely.

pwolanin’s picture

For D7 I guess we allowed an extra level or two for router items - so these paths will work, though note that that there is some potential performance penalty for longer paths.

sun.core’s picture

Status: Needs review » Needs work

The last submitted patch, 843162-taxonomy-vocab-paths-17.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new15.89 KB

Simple re-roll of the patch. Only had a single failed hunk in taxonoy.admin.inc.

I'm however wondering if this isn't an API break.. userpoints.module for example contains a link to the vocabulary page which it has defined and this patch is going to break that I think :)

jhodgdon’s picture

Yes, I imagine it is too late to fix this in Drupal 7 by changing the paths.

We could conceivably "fix" this by not allowing people to save vocabularies whose machine names are "list" or "add".

scott falconer’s picture

Patch #1 prevents vocabularies with machine names "list" or "add", but as others have mentioned we'd need to make sure we're blocking all problem names.

The other options I see are:
Modify problem machine names to something like "list_0".
Treat 'list' and 'add' as machine-names that are already is use and follow the same steps that occur if a user tries to create two vocabularies with duplicate machine-names.

jhodgdon’s picture

StatusFileSize
new2.07 KB

Back to the idea of patch #1 then....

I took a look at taxonomy_menu(), and I'm quite certain that 'list' and 'add' are the only problematic vocabulary names.

So the ideas that have been proposed to solve this problem this are:
- Patch #1 - in validation for the vocabulary add/edit form, throw a form error if the machine name is 'list' or 'add'
- Patch #22 and others - changing paths - bad at this stage of D7
- Treat 'list' and 'add' as machine names that are in use and do whatever they do - I think this would be bad from a UI perspective, because the user will not understand what it means. For instance, they create their first vocabulary and happen to call it List, and it says "machine name list is already in use" or some such error message - that would be confusing.
- Modify machine names automatically - I also think this is not a good idea. We should let the user deal with the problem, not guess at a solution.

The problem is, the patch in #1 will not apply, because the form validate function that it was modifying no longer exists. The validation is now happening only in form_validate_machine_name(), which is calling taxonomy_vocabulary_machine_name_load() in order to verify that the machine name doesn't already exist.

So instead what we'd need to do is add an additional #validate to the form, and put in those 5 lines from patch #1.

Here's a patch. It works for me on my test box - prevents adding 'list' or 'add' machine names, but doesn't prevent anything else. Sorry, I couldn't resist also bringing the docblocks up to standards, since I needed to put some @see lines in there... hope that's OK.

berdir’s picture

I'm wondering if this is something that we might want to add to the generic machine_name validate function? I guess there are more forms with machine_names which need a similiar validation, I myself have a module that does...

Looking at #902644: Machine names are too hard to implement. Date types and menu names are not validated, there are several #machine_name_something properties that allow to fine-tune the validation and other things. Theoretically, I guess it would be possible to do this through the regular expression but that is quite complicated. Maybe we could add something like this:

'#machine_name_blacklist' => array('list', 'add')

Also..

+    form_set_error('machine_name', t('The machine-readable name cannot be "add" or "list".'));

I don't think that we can add new strings at this point, string-freeze and so. Obviously it would be better UX than a generic "This machine name is not valid" error message but I guess we'll have to live with that...

I can create a patch, just wanted to ask for feedback before doing that...

Status: Needs review » Needs work

The last submitted patch, 843162-25.patch, failed testing.

jhodgdon’s picture

I don't think there is an existing string error message that will do. Take a look at http://api.drupal.org/api/drupal/includes--form.inc/function/form_valida... -- you will see that all the messages there are quite specific. So the choices will be to use a message that is misleading/incorrect, ot to add a new string.

I do like your idea of adding a name blacklist to the machine name element as a better way to solve this.

And I'm not sure why the test failed. The function works just fine on my test machine.

a.mikheychik’s picture

Status: Needs work » Needs review
StatusFileSize
new2.12 KB

Small update of patch: we should check is the machine name key is set, because this validation also passing during deletion, that's wy test crashes with Notice

jhodgdon’s picture

+1 on this patch. Doc is good anyway.

mtift’s picture

StatusFileSize
new2.52 KB

Previous patch failed. Re-rolled patch from root to fix file paths.

Dave.Ingram’s picture

Status: Needs review » Reviewed & tested by the community

Applied patches, ran tests, and tested all the validation functionality of the patch. Looks ready to go!

jhodgdon’s picture

Version: 7.x-dev » 8.x-dev

Needs to go to d8 and then d7

catch’s picture

Issue tags: +Needs backport to D7

tagging for backport.

dries’s picture

I'm willing to commit this patch in order to make progress with 7.x and 8.x. However, I'm not sure this is the most elegant fix for 8.x. Once we get this in in 7.x and 8.x as a stop gap solution, should we try to resurrect http://drupal.org/node/843162#comment-3912612 for D8? I'm recommending that we do.

dww’s picture

Note to anyone that lands here looking at the Git commit history for the Update manager. Dries accidentally committed the fix for #1008328: Uniqueify update-cache and update-extraction directories to prevent "Permission denied" errors as http://drupalcode.org/project/drupal.git/commit/02dd3c5 which said:

- Patch #843162 by pwolanin, Scott Falconer, Berdir, jhodgdon, a.mikheychik, mtift: creating vocabularies with machine-names 'List' or 'Add' breaks links in taxonomy overview admin area.

Just leaving a pointer in case anyone ever tries to sort out the Git archeology and is wondering WTF happened... ;)

Cheers,
-Derek

jhodgdon’s picture

RE #35 - agreed, for d8 we should eventually change the paths like the patch in #22 above. But probably not for D7.

dries’s picture

Priority: Major » Normal

Committed this patch to 7.x and 8.x. I'm changing the status field to 'needs work' and lowering the priority so we can discuss code clean-ups for 8.x.

berdir’s picture

Status: Reviewed & tested by the community » Needs work

Setting status to needs work (or should it be active? not sure..)

andypost’s picture

Issue tags: -Needs backport to D7

Is this a good issue to change a router paths all over core? suppose we should start new one and change all menus to format:
.../[module-entity]/[action]/[machine name and other parameters]

Also this could not be backported to D7 because of contrib modules that already use current paths.

jhodgdon’s picture

I think if you want to change router paths all over core (again -- there were a LOT of changes for D7 too), it should be a separate issue.

andypost’s picture

andypost’s picture

andypost’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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