Ticket #4165 (closed defect: fixed)

Opened 2 years ago

Last modified 1 year ago

Info regex is too greedy

Reported by: kapoylski Assigned to: rob1n
Priority: low Milestone: 2.3
Component: Administration Version: 2.1
Severity: normal Keywords: has-patch
Cc:

Description

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 );

to:

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

4165.diff (3.1 kB) - added by rob1n on 06/01/07 02:58:52.
might as well do them all

Change History

04/18/07 22:08:22 changed by foolswisdom

  • milestone changed from 2.4 to 2.3.

04/19/07 19:15:32 changed by Otto42

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.

06/01/07 02:56:41 changed by rob1n

  • keywords set to has-patch.
  • 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.

06/01/07 02:58:52 changed by rob1n

  • attachment 4165.diff added.

might as well do them all

06/01/07 02:59:17 changed by rob1n

New patch does theme, template and plugin get info functions

06/01/07 03:03:31 changed by rob1n

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

06/02/07 00:02:07 changed by rob1n

  • status changed from assigned to closed.
  • resolution set to fixed.

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