#31135 closed defect (bug) (fixed)
register_taxonomy() should call a _doing_it_wrong() when called with an empty taxonomy name
Reported by: | tyxla | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 4.2 | Priority: | normal |
Severity: | minor | Version: | 3.0 |
Component: | Taxonomy | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
If you misuse register_taxonomy()
with an empty string as a first parameter, this will currently not throw any notice.
Anyway, it is definitely wrong and can lead to some very weird results both in the administration and in the frontend.
I suggest that a _doing_it_wrong()
should be called to cover this case.
Attachments (5)
Change History (16)
#2
@
10 years ago
- Keywords needs-unit-tests added
- Milestone changed from Awaiting Review to 4.2
- Severity changed from normal to minor
- Type changed from enhancement to defect (bug)
Hi @tyxla, thanks for the patch, that's a good catch. I think we can probably modify the existing _doing_it_wrong()
call to account for both cases, maybe "Taxonomies must be between 1 and 32 characters in length." We also need a unit test covering the empty string case.
@
10 years ago
Updating the first patch. Now using a single _doing_it_wrong()
call for both taxonomy min and max, also adding unit tests for both cases.
#5
@
10 years ago
Just a couple of things on 31135.2.patch:
- Rather than tacking tests on to the main
test_register_taxonomy()
method, you should split them out to more specifically-named tests. For instance, the "> 32 characters" case is already covered bytest_register_long_taxonomy()
a few lines below your changes - Realistically, we're checking for the returned
WP_Error
object instead of a_doing_it_wrong()
to confirm the test, see below for an example of this:<?php /** * @ticket 21593 * * @expectedIncorrectUsage register_taxonomy */ function test_register_long_taxonomy() { $this->assertInstanceOf( 'WP_Error', register_taxonomy( 'abcdefghijklmnopqrstuvwxyz0123456789', 'post', array() ) ); }
- So perhaps creating a
test_register_short_taxonomy()
block might be the way to go. I'd follow the same syntax as for long
#6
@
10 years ago
Thanks for making things more clear on how _doing_it_wrong()
cases are tested. And I really missed the test_register_long_taxonomy()
test.
Updating the patch with your suggestions right away.
#7
@
10 years ago
- Keywords commit added
- Owner set to SergeyBiryukov
- Status changed from new to reviewing
Related: #28683
Adding a
_doing_it_wrong()
whenregister_taxonomy()
is called with an empty taxonomy name.