Make WordPress Core

Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#3674 closed defect (bug) (fixed)

WordPress Admin Theme Editor Right Sidebar drops files from template list.

Reported by: gjorgensen's profile gjorgensen Owned by:
Milestone: 2.1.1 Priority: high
Severity: major Version: 2.1
Component: Administration Keywords:
Focuses: Cc:

Description

This ticket includes both the problem introduced in version 2.1, and the (very easy) bug fix to wp-admin/admin.functions.php.

For full text and sample screen shots please visit http://gilbertjorgensen.com/2007/01/24/wordpress-21-admin-theme-file-patch/

The screenshots make the problem obvious.

In the Admin Theme Editor, I could mouse over the right side listing of templates and the screen would indicate that they were there by providing highlighted vertical bars at the ends of the lines, but the text was missing.

Deciding that this was unacceptable, I did a little research to determine what had changed and found the offending line. It seems that in the new 2.1 release there has been an attempt to make the code more readable by adding spaces around field names, etc. In most cases that doesn’t create any problem, however in a regular expression it can produce unexpected results.

Starting at line 1597 of wp-admin/admin.functions.php we have the following code:


function get_file_description( $file ) {

global $wp_file_descriptions;

if ( isset( $wp_file_descriptions[basename( $file )] ) ) {

return $wp_file_descriptions[basename( $file )];

}
elseif ( file_exists( ABSPATH . $file ) && is_file( ABSPATH . $file ) ) {

$template_data = implode( , file( ABSPATH . $file ) );
if ( preg_match( "|Template Name:(.* )|i", $template_data, $name ))
return $name[1];

}

return basename( $file );

}


Notice specifically line 1605 which says:


if ( preg_match( "|Template Name:(.* )|i", $template_data, $name ))


Line 1605 instructs the PHP regular expression parser to match against the string “|Template Name:(.* )|i”. Notice how we have in parenthesis (.* ), e.g. a left parenthesis, a period, and asterisc, a space, and a right parenthesis. The space is the culprit. Take the space out so we have (.*), and our list or WordPress templates will display just fine.

I did a “Search all files” with my UltraEdit text editor and did not find any other “preg_match” occurances with offending spaces in the new WordPress 2.1 release.

Change History (5)

#1 @Znuff
18 years ago

  • Milestone changed from 2.3 to 2.1.1
  • Version set to 2.1

#2 @foolswisdom
18 years ago

gjorgensen, awesome work! Please attach a patch!

#3 @markjaquith
18 years ago

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

(In [4809]) Template Name: regex fixup by gjorgensen. fixes #3674

#4 @markjaquith
18 years ago

(In [4810]) Template Name: regex fixup by gjorgensen. fixes #3674

#5 @markjaquith
18 years ago

Gold star for gjorgensen. :-)

Note: See TracTickets for help on using tickets.