Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This is a sub-part of the larger patch proposed here: http://drupal.org/node/88633
Go ahead- I dare you. Create a new node type and give it the machine-readable name 0 (just the number zero).
This problem occurs because the validation for "required" form values allows the string '0', but in PHP empty('0') == TRUE
, so all the checks for empty() (or not empty()) $type->type values don't work.
Attached patch returns a validation error if the $type->type evaluates to empty. This is the simplest thing I can think of that does not break any existing t() strings.
Comment | File | Size | Author |
---|---|---|---|
#6 | empty_type_validate_3.diff | 922 bytes | pwolanin |
#3 | empty_type_validate_2.diff | 969 bytes | pwolanin |
empty_type_validate_1.diff | 873 bytes | pwolanin | |
Comments
Comment #1
Jaza CreditAttribution: Jaza commentedThis is about the simplest solution that we can implement for catching this uncommon edge case. I think that other possible solutions, such as enforcing a minimum length of 2 chars for node type names, is overdoing it.
RTBC.
Comment #2
drummThe error message, "Invalid machine-readable name 0," is not helpful. Why isn't this valid? What can be done to fix it? Why is it 'machine-readable' in the message but the field is labeled 'type'?
Comment #3
pwolanin CreditAttribution: pwolanin commentedHere's an improved error message.
Comment #4
pwolanin CreditAttribution: pwolanin commentedsince the text seemed to be the only problem, setting back to RTBC
Comment #5
ChrisKennedy CreditAttribution: ChrisKennedy commentedThe comment should go on its own line imo.
More importantly, the error message is inaccurate: "Please use a type name with more than one character, or a character other than zero."
As far as I can tell there is no requirement that the type be more than one character. I think you're trying to say that it needs to be at least one character, and also cannot be '0'. However, I this message need only occur if the type is zero itself, because #required is already set to TRUE for $form['identity']['type'], so we know that it isn't a truly empty string. See _form_validate().
If I'm right, the error message should be something like: "Please choose a type name other than '0'." This also suggests that the comment should be modified, and you might as well make the if test be === '0' to be clearer.
Comment #6
pwolanin CreditAttribution: pwolanin commentedFYI, in form.inc, the code validating "required" fields in _form_validate() is:
revised patch attached for this annoying edge case.
Comment #7
ChrisKennedy CreditAttribution: ChrisKennedy commentedUpdated patch looks good and works as designed.
I hope in d6 we can remove the lazy empty(), etc. checks throughout core that create these edge cases. That is an issue for another day.
Comment #8
drummCommitted to HEAD.
Comment #9
(not verified) CreditAttribution: commented