Make WordPress Core

Opened 17 years ago

Closed 17 years ago

#4499 closed defect (bug) (fixed)

Equality checks in query.php can break permalinks

Reported by: agharbeia's profile agharbeia Owned by: markjaquith's profile markjaquith
Milestone: 2.3 Priority: high
Severity: major Version: 2.2
Component: General Keywords: has-patch
Focuses: Cc:


According to this,
there is bug in the way WP 2.2 handles permalinks consisting only of date/time elements.

The blog in which the problem manifests uses the permalink structure /%year%/%monthnum%/%day%/%hour%%minute%%second%

In this case WP fails to uniquely identify a post whose %hour% permalink tag resolves to zero, and resorts instead to displaying the archive page for the calendar day in which the post referred to by the permalink was published, which in turn means that is_single() will always resolve to false and that no single post page can ever be obtained.

Posts having anything other than zero in their %hour% of publication will resolve normally.

Please note that unlike some people might first assume, this permalink structure worked in versions before 2.2. WordPress was indeed able to handle permalink structures which do not have neither %post_id% nor %postname%

Attachments (1)

4499-trunk.diff (2.3 KB) - added by markjaquith 17 years ago.
Patched based on Otto42's modified query.php file (for trunk)

Download all attachments as: .zip

Change History (10)

#1 @foolswisdom
17 years ago

  • Milestone set to 2.3 (trunk)

#2 @agharbeia
17 years ago

  • Summary changed from problem in permalinks consisting solely of date/time elements to permalink unresolvable when it consists solely of date/time elements

#3 @Otto42
17 years ago

  • Priority changed from normal to high
  • Severity changed from normal to major
  • Summary changed from permalink unresolvable when it consists solely of date/time elements to Equality checks in query.php can break permalinks

This is due to all the instances in query.php where it's checking for things like this:

if ( '' != $q['hour'] ) ...

The empty string == zero, in php. Evidence:

<?php if ('' == 0) echo "equal"; else echo "not equal"; ?>

All these checks need to be changed from != to !== in order to test for identity instead of equality.

Note that he would get the same result for minute == 0 or second == 0 as well. There are also possibly other equality checks that can result in broken links like this.

#4 @rob1n
17 years ago

  • Milestone changed from 2.3 (trunk) to 2.2.2

Should be a simple search+replace.

#5 @rob1n
17 years ago

  • Keywords needs-patch added

#6 @Otto42
17 years ago

Can't make a patch at the moment, however I made a modified copy of query.php, and the original poster says it works. It can be found here:

17 years ago

Patched based on Otto42's modified query.php file (for trunk)

#7 @markjaquith
17 years ago

  • Keywords has-patch added; needs-patch removed
  • Milestone changed from 2.2.2 to 2.3 (trunk)
  • Owner changed from anonymous to markjaquith
  • Status changed from new to assigned

We have to fix it in trunk before we can even consider fixing it in 2.2.2

4499-trunk.diff is a diff based on Otto42's modified query.php

Look good?

#8 @Otto42
17 years ago

Looks good to me, mark. It may not fix all of the possibles of this issue, but it does fix the hour/minute/second ones.

#9 @markjaquith
17 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [5848]) Allow for hour/minute/second values in the QS that evaluate as false (like 0). Props Otto42 and agharbeia. fixes #4499

Note: See TracTickets for help on using tickets.