Make WordPress Core

Opened 17 years ago

Closed 17 years ago

#4165 closed defect (bug) (fixed)

Info regex is too greedy

Reported by: kapoylski's profile kapoylski Owned by: rob1n's profile rob1n
Milestone: 2.3 Priority: low
Severity: normal Version: 2.1
Component: Administration Keywords: has-patch
Focuses: Cc:


In the WordPress admin, under Write > Write Page there is a drop-down box for selecting the page template. When I create my own page templates and add them, the box lists them, but includes extra characters alongside the name. If I alter the regular expression used in get_page_templates() in the admin_functions.php on line 1247 file from:

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


preg_match( "|Template Name:([^\*]*)|i", $template_data, $name );

It no longer includes the characters. I assume the preg_match statement is just matching too much and returning it as the template name. I'm attaching the two template files that exhibit this problem, as well as a screen-shot of what I'm seeing.

Attachments (1)

4165.diff (3.1 KB) - added by rob1n 17 years ago.
might as well do them all

Download all attachments as: .zip

Change History (7)

#1 @foolswisdom
17 years ago

  • Milestone changed from 2.4 to 2.3

#2 @Otto42
17 years ago

Would this line work instead?

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

Your line excludes asterisks from the match, whereas mine explicitly specifies the end of line outside the matching string. I don't know why yours continues to match beyond the end of the line, but this might work as well and still allow * characters in the Template Name.

#3 @rob1n
17 years ago

  • Keywords has-patch added
  • Owner changed from anonymous to rob1n
  • Status changed from new to assigned

The PREG "m" modifier treats the multi-line string's lines as each a string (see here). Thus, the $ would match the end of the line.

17 years ago

might as well do them all

#4 @rob1n
17 years ago

New patch does theme, template and plugin get info functions

#5 @rob1n
17 years ago

  • Summary changed from Page template names include code to Info regex is too greedy

#6 @rob1n
17 years ago

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

(In [5630]) Keep greedy regex's in control. fixes #4165

Note: See TracTickets for help on using tickets.