Make WordPress Core

Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#2321 closed defect (bug) (fixed)

Array union in generate_rewrite_rules doesn't achieve expected effect.

Reported by: majelbstoat's profile majelbstoat Owned by: ryan's profile ryan
Milestone: Priority: normal
Severity: normal Version: 2.0
Component: General Keywords: rewrite rules array union bg|has-patch
Focuses: Cc:

Description

Line 1287 of classes.php:

$post_rewrite = $rewrite + $post_rewrite;

doesn't actually assign what you would expect ($rewrite followed by $post_rewrite) to $post_rewrite. It in fact assigns ($post_rewrite followed by $rewrite). The difference is subtle, but can be important for plugins that wish to generate their own rewrite rules.

An example of the problem with assignments this way is at:

http://jamietalbot.com/wp-hacks/miscellaneous/arrayuniontest.php

From this example, you can see that assigning the result to a new variable achieves the intended order. The patch supplied assigns the result temporarily to a new variable and then immediate copies it back to $post_rewrite, which fixes the problem for me on PHP versions 4.3.4 and 4.3.11.

Attachments (2)

array union assignment fix.diff (479 bytes) - added by majelbstoat 19 years ago.
Patch to ensure that the rewrite arrays are correctly unioned
array_merge to replace array union.diff (2.8 KB) - added by majelbstoat 19 years ago.
Alternative patch that replaces unions with array_merge

Download all attachments as: .zip

Change History (8)

@majelbstoat
19 years ago

Patch to ensure that the rewrite arrays are correctly unioned

#1 @ryan
19 years ago

We should probably change all of those unions to use array_merge instead.

#2 @majelbstoat
19 years ago

I thought about that, but it does involve the overhead of a function call, when it is only a simple prepend...

@majelbstoat
19 years ago

Alternative patch that replaces unions with array_merge

#3 @majelbstoat
19 years ago

In any case, here is a patch that converts all the array union operators in classes.php to an array_merge call. There were 6 or 7 in total, making it a more comprehensive patch than the previous one. Assuming the overhead of a function call is negligible this would be a better solution. In any case, you can decide which one to use. Tested and working on PHP 4.3.4 and 4.3.11 on latest SVN.

#4 @ryan
19 years ago

  • Owner changed from anonymous to ryan

#5 @ryan
19 years ago

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

(In [3472]) Use array_append() instead of unions. Props majelbstoat. fixes #2321

#6 @(none)
18 years ago

  • Milestone 2.0.1 deleted

Milestone 2.0.1 deleted

Note: See TracTickets for help on using tickets.