I got message:
<>
But menu title (as typed) length is only 6(six) characters.
The software error is obvious, in my opinion.
The Control page URL:
http:///?q=admin/build/menu-customize/menu-articles-additional-menu
I use Cyrillic translation of drupal strings.
PHP Version 5.2.6-2
Apache/2.2.9 (Debian) PHP/5.2.6-2 with Suhosin-Patch
PHP Mbstring is functioning.
| Comment | File | Size | Author |
|---|---|---|---|
| #80 | 292790-80-menu-validation.patch | 1.32 KB | jonathan1055 |
| #69 | 292790_69_menu_name_validation.patch | 1.39 KB | ñull |
| #68 | 292790_68_menu_name_validation.patch | 1.34 KB | ñull |
| #63 | 292790-63-menu-validation.patch | 1.32 KB | jonathan1055 |
| #58 | 292790-60-menu-validation-D6.patch | 1.32 KB | jonathan1055 |
Comments
Comment #1
ag888 commentedThe message (was lost by drupal by formatting case):
---
The menu name can't be longer than 27 characters.
---
Comment #2
mikael37 commentedI experience the same problem and here are more info :
the problem occurs when the the NAME of the menu (and not the TITLE of the menu) is more than 22 characters length. I've made several tests, and when the name of the menu is 23 characters length or over the problem occurs.
Note that the length of 22 characters is 27 - 5. And 5 seems to be the length of the menus prefix "menu-". Can it help ?
In the case of ag888 it is certainly the same problem because according to the link "http:///?q=admin/build/menu-customize/menu-articles-additional-menu" that is used to manage the menu we can see that the name of the menu "articles-additional-menu" is 24 characters length.
Comment #3
kjay commentedI've also been creating some menus with long names and found them to have this same bug. I took a look through the code and whilst I'm new to contributing, I think I can see the problem.
When first creating a new menu the menu_edit_menu_validate function prepends the menu name with the string 'menu-', which is then stored to the db.
The validation script for checking the length of the menu name (which is limited to 32 characters in the table) checks for a string that is not greater than 27 characters, set by the value of MENU_MAX_MENU_NAME_LENGTH_UI. Since this validation is always called when submitting the menu settings form, whether creating a new menu or editing an existing one, it is the case that the value for 'MENU_MAX_MENU_NAME_LENGTH_UI' needs to be adjusted depending on whether saving or editing the form. When saving the a new menu we are checking against the value of 27 characters, when editing the form we need to be checking against the value of 32 characters because we have to allow for the 'menu-' string having been added.
Since the menu name is not something that can be changed when editing the menu it would be simpler to bypass validation of the menu name in any state other than 'create new menu'. However, I do not know if this is best practice since it is making presumptions about how this function is being used. I have therefore written a patch that adjusts the value max length based on mode.
Here is a patch that is for the modules/menu/menu.admin.inc file. I am a beginner and I'm not sure the patch is working as easily as it should in terms of locating the file, when I tested it I had to prompt it with which file to update. I'll try again at making a better path. Any help would be appreciated thanks.
Comment #4
casperl commentedDitto, same bug here. Everything I use is the very latest and greatest as of today ie Drupal 6.6 etc and this is the first Drupal 6 site I am doing.
Except for this little bit:
This "BUG!" was reported on August 8, 2008. It is now 18 November 2008 and the status on this is still unassigned. There is patch code and it is yet to be reviewed.
AFAIK the menu system is a critical part of Drupal and is certainly a core function.
Is someone going to "fix" this?
Comment #5
kjay commentedYes, I am also surprised that a bug in the menu system like this isn't getting a little more attention... I guess folks are using short titles! It is my first patch and I am keeping an eye on the thread to see if I'm doing things the right way. Please review someone?
thanks
Comment #6
kjay commentedpatch review.... please someone? :-)
Comment #7
myDRU commentedSubscribing.
Comment #8
code-brighton commentedPlease note this also appears to happen in the bookmark module for Drupal 6.
I tried to delete a bookmark with a name of about 22 characters and it threw up an error message and I was unable to delete.
I applied the same principle to modifying the file bookmarks.admin.inc as described in the patch created by kjay and it seemed to work.
Also note that I changed the defined variable MENU_MAX_MENU_NAME_LENGTH_UI in the bookmark module to BOOKMARK_MENU_MAX_MENU_NAME_LENGTH_UI otherwise it keeps the value of 27 set in menu.module not the 23 set in bookmarks.module!
Not sure how to properly make a patch, but code changes in bookmarks.admin.inc as follows:
if (preg_match('/[^a-z0-9-]/', $item['menu_name'])) {
form_set_error('menu_name', t('The menu name may only consist of lowercase letters, numbers, and hyphens.'));
}
// adjust max name length based on insert or edit
$name_length = BOOKMARK_MENU_MAX_MENU_NAME_LENGTH_UI;
if (!$form['#insert']) {
$name_length = BOOKMARK_MENU_MAX_MENU_NAME_LENGTH_UI + 9;
}
if (strlen($item['menu_name']) > $name_length) {
form_set_error('menu_name', format_plural(BOOKMARK_MENU_MAX_MENU_NAME_LENGTH_UI, "The menu name can't be longer than 1 character.", "The menu name can't be longer than @count characters."));
}
if ($form['#insert']) {
And make sure you replace the other instance of MENU_MAX_MENU_NAME_LENGTH_UI with BOOKMARK_MENU_MAX_MENU_NAME_LENGTH_UI in the same file and in bookmarks.module
Comment #9
jonathan1055 commentedThis bug was first noticed in April 2008 in Drupal version 6.2 and several users have confirmed it.
Kjay did a great job in providing us with a patch, which has been tested, but it has not been incorporated as of now (D6.8). I have applied the patch code lines manually to my 6.8 installation and it does the job perfectly. I have not tested the automated 'apply patch' procedure http://drupal.org/patch/apply
I am not sure of the next step to get this implemented. It is a very simple code correction, but if not done it really causes havoc, and you end up with un-deletable duplicate menus.
Comment #10
scottrigbyPatch applies with no fuzz on D6.8 – and works as promised.
It sounds like this patch has been reviewed – too early to mark RTBC?
Comment #11
gábor hojtsyShould first be committed to Drupal 7 and then to Drupal 6, so we ensure that the fix is in the latest version and we are not going to have any regressions.
Comment #12
Panchobook commentedI'm 6.10 and the bug is still not fixed. But the patch works. Thanks, kjay!
(off topic) The numbering system for Drupal revisions is also a bit confusing. 6.10 is more advanced than 6.9? (/off topic)
Comment #13
mr.baileysPatch against HEAD attached. I don't think the fix in #3 is the best way to resolve this: the machine name for the menu is only entered during the insert phase, so it does not make sense to validate it on the edit screens. Hence there is no need to work with 2 different max length settings.
Also tagging this "Review Exchange": you scratch my back, I'll scratch yours. I'll happily review a patch of similar size for someone who reviews this one.
Comment #14
damien tournoud commentedThis will need a test for D7.
Comment #15
mr.baileysDo you mean a regression test (verifying that the incorrect validation message is no longer displayed after change) or just testing the validation message in general?
Comment #16
mr.baileysmmm, didn't mean to set it back to CNR....
Comment #17
mr.baileysOk, new patch, this time with some tests included:
Comment #18
dave reidRemoving the Review Exchange tag. All our reviews work the same way. It's just implied.
Comment #19
mr.baileysCool. I wasn't aware that this was an unwritten rule in the community.
Comment #20
mr.baileys@kjay: I just noticed that you offered the solution of removing the validation on anything but inserts:
So the answer is yes, in this case I think moving the validation to inside the "insert" logic is the best thing to do :)
Comment #21
benansell commentedIs this fixed in 6.10? I'm seeing the same error message. Can't rename, or delete existing menus ..... If someone could advise, it would be appreciated.
Thanks.
Comment #22
jonathan1055 commentedIt is not fixed in 6.10, but you can use the patch in #13 to make the change. The patch in #17 makes the same change to the executable code but also makes changes to the .test file which you will not have, so that is why I suggest you use the patch in #13.
Actually, it is just a move of one line 'if ($form['#insert']) {' so you could edit function menu_edit_menu_validate() in /modules/menu/menu.admin.inc manually.
Jonathan
Comment #23
jonathan1055 commentedI have tested the patch given in #17 on my D6.10 site. Obviously I have to skip the first file to be patched as I dont have the menu.test file. But the second change works fine, accepting the fuzz of 2. It is exactly the same code change as in #13.
I have tested the change by adding menus with machine length of 21, 22, 26, 27 and can edit the description afterwards, all fine.
Entering a new menu with machine name length 28 gives the error message as expected.
It seems that we are all agreed that this correction is the proper way to fix it, my manual testing in D6 is fine, and it passed the automated D7 tests. So I have marked this as 'reviewed & tested'.
Jonathan
Comment #24
mr.baileysbump.
Comment #25
dries commentedCommitted to CVS HEAD. Thanks!
Comment #26
wretched sinner - saved by grace commentedI think there is a request to look at this for D6 too...
Comment #27
catchNeeds a re-roll to remove the test hunk.
Comment #28
Jeff Burnz commentedBump, forgive the bump, this is plaguing a number of my Drupal sites, it would be great to have this in the next D6 release.
Comment #29
jonathan1055 commented@jmburnz You can download the patch in #13 which works with D6, or you can make the change manually as described in #22, but its easier to download the pacth, then you can re-apply it to every Drupal upgrade until it is included in the official release.
Comment #30
Jeff Burnz commentedYes, I have patched a few of my sites that have this issue, but some I am loath to because I have to hand them off to someone else, but I'll do what it takes right now - patch it is!
Comment #31
recidive commentedHere's the patch for Drupal 6.
Comment #32
jonathan1055 commentedYes, this patch installs cleanly in D6.14 and the change is identical to the previous patches tested on D7 and D6, as above (see my testing in #23).
But do you know why did this one not get submitted for automated testing?
Comment #33
recidive commented@jonathan1055: AFAIK automated tests are only for Drupal 7+ patches. Can you please mark this as "reviewed & tested by the community"?
Comment #34
jonathan1055 commentedOK with me.
Comment #35
hedac commentedthank you for the patch... working
Comment #36
Onehorse commentedNewbie to Drupal and Open Source in general here, so please forgive my process ignorance and likely lack of decorum...If I am reading the posts and statuses correctly it looks like the issue is agreed upon but there are two approaches to the fix offered? I see no reference to an automated patch in the offing, so I have applied the changes by hand as noted in the diff as provided in in #31 above.
This passed the UCT Battery (unsophisticated customer test that didn't batter me *innocent grin*)
It cleared up the problem I was experiencing with no visible side effects. THANK YOU ALL!
For future reference, is there a onestop reference where I can learn how to participate in the process appropriately? For instance, should I have patiently waited for some kind of formal announcement of an auto install patch? Mostly, I don't want to patch up my code in a way that will interfere with future releases...is there an established set of best practices I should be following?
Comment #37
gábor hojtsyMy immediate reaction was that this does not do length validation on editing menu items anymore. The reason it was in the general part of the function was to always validate length. So you could update to a name longer then allowed when editing a menu? Wait, no, the form item already has a #maxsize property set. So then, is it not displaying two error messages when the length exceeds the allowed characters?
If it does not do two messages, then seems like we miss validation on editing an item, if it does, looks like the initial submission is clumsy. Either way, we have stuff to improve here I think.
Comment #38
mr.baileys@Gabor:
Thanks for your feedback:
This field (Menu name) is only present on the "insert" form. When editing you are not allowed to change the machine name, and the form element is missing. If I recall correctly, this is the root cause of the issue: insert allows you to add menu names up to 27 characters, and after validation prepends the machine name with "menu-" before inserting it in the database. The edit form then does not allow you to change the menu name (the machine name element is missing entirely), but it does try to validate the machine name, resulting in an error since the machine name is now 27 + 5 characters ==> too long.
Hence the reason for moving the length validation to inside the insert logic...
Actually it doesn't, but you do bring up an interesting point, why isn't Form API taking care of validating the field length. Turns out #maxsize is not a valid property for a textfield, it should actually be #maxlength. Changing #maxsize to #maxlength and removing the length validation from menu.admin.inc entirly fixes this issue and keeps validation intact.
I'll try and roll a D7 patch later today...
Comment #39
mr.baileysPatch attached which removes the validation and relies on Form API length validation. Slightly altered test to accomodate the changed error message.
Comment #40
malc0mn commentedStill present in D6 ofcourse... D6 patch attached, just to get some activity back in the thread ;-)
Comment #41
aspilicious commented#39 still applies for D7
Comment #42
malc0mn commentedPatch hasn't been added to HEAD yet I guess... But then again, there are other more urgent issues I bet :-)
Comment #43
roborracle commentedCan I get some specific direction on how to apply this patch? I've found this section of code in the menu.admin.inc file, but I'm not sure if it should all be replaced, or if I should add only the patch at the bottom of the document, etc. etc.
If anyone could offer a little insight on how I need to apply this patch, I'd appreciate it!
Comment #44
roball commentedBug still exists in D6.16 - just got hit from it.
Comment #45
klausitrailing whtiespace
Powered by Dreditor.
Comment #46
Anonymous (not verified) commentedIn the patch there are some lines with '-' front of them and some with '+'. In that area of code just delete the lines with the minus sign in front of them and add the lines with an addition sign.
Patch in #40 worked for me. Kinda annoying that with a ready solution that this isn't included in the core already.
Comment #47
roball commentedPatch in #39 must first be committed to D7, then the D6 port may be committed to D6. Thus the version number should be kept on 7.x for now.
Comment #48
ambientdrup commentedJust to confirm - the patch for D6 in #40 works for latest version of D 6.17. When can we get this committed to core D6?
-backdrifting
Comment #49
ambientdrup commentedShouldn't we commit to D6 version first since D7 is still in production?
-backdrifting
Comment #50
aspilicious commented#39: 292790-menu-validation-D7.patch queued for re-testing.
Comment #51
aspilicious commentedFirst we fix bugs in D7 than backporting. :)
Comment #52
aspilicious commentedWell test will fail here a reroll :)
+ removed trailing white space
Comment #53
hessam61 commentedComment #54
TimG1 commentedsubscribing
Comment #55
j0nathan commentedSubscribing.
Error encountered on a Drupal 6.16.
Comment #56
jonathan1055 commentedSomething slightly confusing has happened here regarding the D7 fix.
Just to remind everyone, the patches in #39 and #52 have the same solution to menu.admin.inc but the code in menu.test for #52 was cleaned up to remove trailing whitespace.
I've just checked the souce code in D7 beta3 and it appears that the substance of the #39/#52 patches has been committed. The code in D7-beta3 menu.admin.inc is as expected from the patch, but it is odd that nothing has been announced on this thread about it being committed.
The code in menu.test is not exactly the same as either of the patches, because it has been reformatted with the array values on new lines, and the second parameter passed to $this->assertRaw has been removed.
So as I see it, the D7 code has been committed, and we can set this thread back to 6.x-dev and get the patch committed here too. BUT I want someone else to confirm what I've discovered above before I change the version.
It's been 2 years and 3 months since discovering the problem, but we WILL get this fix committed to D7 and D6, yes we will :-)
Jonathan
Comment #57
mr.baileysLooks like the D7 fix was part of #902644: Machine names are too hard to implement. Date types and menu names are not validated
Comment #58
jonathan1055 commentedWow, what a thread #902644: Machine names are too hard to implement. Date types and menu names are not validated was! I've just read through it, 101 posts in 8 weeks.
Yes, this issue is now fixed in D7 so we can turn our attention to D6. The code change in the patch in #40 is what needs to be implemented, but that was created in 6.15 or 6.16. The file menu.admin.inc changed in 6.17 but has not changed since then, up to the latest 6.19 dev, so I've re-rolled that patch.
Please can some of you in the thread above test this patch, then we can hopefully finally get it committed in D6.
Jonathan
Comment #59
tanjerine commentedsubscribing and will try patch.
[edit] and patch seems to be working nicely. thank you.
Comment #60
Mark Schneider commentedYes, patch works fine for me, too. Thanx for the solution.
Comment #61
jvieille commentedThis problem pops up almost systematically with OG Menu
Perfect (after 2 years...)
Thanks
Comment #62
mennowas commentedI tried to delete a menu item that I put at the same level as primary links et cetera. I wasn't able to delete that menu item without getting this message: "The menu name can't be longer than 27 characters". I found my solution to delete the menu item in the topic "How to delete a menu" http://drupal.org/node/245930. You have to click on the menu item and add the word "delete" at the end of the url.
Comment #63
jonathan1055 commentedThe patch in #58 applies cleanly in D6.20 I am attaching the file again, however, to get it tested by the testing bot. I did not realise that if you add any -Dn suffix before the .patch then it will not be tested (even if that number matches the version of the issue).
Comment #65
jonathan1055 commentedHmm... any ideas? the patch was against a file which has not changed since 2nd June 2010, as is still at this date in the latest 6.x dev of 16th Dec 2010. Is the format of the patch file wrong? The other patches above contain
Comment #66
ñull commentedWhen is this getting somewhere near approved? I don't like applying patches to core.
Comment #67
jonathan1055 commentedThe solution is decided on, and the coding is done and tested. But it needs a different kind of patch syntax to pass the automated tests. I don't the facility to create this, but someone else on this thread should be able to.
Comment #68
ñull commentedIt is important enough to get fixed soon. So I gave it a try with my environment. May be just the Index statement was missing that I saw in other patches.
Comment #69
ñull commentedanother attempt, now using git diff manually. I checked out dev so I apply the patch to that version, another possible mistake.
P.D. This fails as well. I think that the test only works for D7 development patches. The description here says that it is for HEAD, which is the main development version of Drupal 7.x at the moment. So it seems that D6 development is out of the picture for automatic testing and there is some explanation how to skip testing by letting the patch file end with -D6.patch.
Comment #71
ñull commentedI think this is the correct tag. The patch has been applied to the 7.x branch but is tested and reviewed and now need to be applied to the 6.x branch. Please leave it like this otherwise it never gets applied.
Comment #72
roball commentedI think the patch test bot no longer works with any D6 patches: #961172: All D6 Core patches are failing
Comment #73
jonathan1055 commentedThanks roball, yes that is it.
@null in #71, are you sure the status should be 'patch to be ported'. The patch has already been ported, there is no more coding to be done, it is correct for D6. It needs 'review' then when passed by test bot, it can go RTBC. I've not changed the status because I am quite willing to be wrong on this, just thought I'd ask.
Comment #74
ñull commentedThat was my interpretation of the definition. Rereading it now, I must have been in a hurry. The patch is ready for 6.x so no porting is needed any more. I think you're right that it should be "RTBC"
Comment #75
jonathan1055 commented#69: 292790_69_menu_name_validation.patch queued for re-testing.
Comment #77
mducharme commentedsubscribing
Comment #78
jonathan1055 commentedI have asked on #961172: All D6 Core patches are failing if they can help us get this patch to go green on the testbot. As we know, the code is fine just that automatic testing is not working.
Comment #79
CarbonPig commentedsubscribe
Comment #80
jonathan1055 commented#961172: All D6 Core patches are failing might be fixed now. Or it will be shortly. Lets hope!
Comment #81
jonathan1055 commentedThis is good news. Marking this 'reviewed and tested'.
Do we now have to find someone who can commit this?
Comment #82
gábor hojtsySuperb, now committed and pushed this one thanks.
Comment #83
jonathan1055 commentedThank You! We've waited so long for this, but it has been a good experience for me to help it through.
Thank you to everyone who has contributed.
Jonathan
Comment #85
malc0mn commentedWhoow, just came back (after more than a year since #42, haha) to check this thread, what a hassle this has been for 4 lines of code :-D
Glad it got in though!