WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#19854 closed defect (bug) (fixed)

themes.php doesn't show themes if using Mac-style CR EOL markers

Reported by: novasource Owned by: nacin
Milestone: 3.4 Priority: normal
Severity: normal Version: 3.3.1
Component: Themes Keywords: has-patch
Focuses: Cc:

Description

Apparently Macs by default only use CRs to mark end of lines.

If a child theme's style.css file was saved using this, which can happen in Dreamweaver, WordPress won't even show the child theme at wp-admin/themes.php. This has come up at http://wordpress.org/support/topic/child-themes-doesnt-show-up-in-mamp.

If EOL only with CR isn't supported, it would be nice to at least show a warning.

Attachments (3)

19854.diff (544 bytes) - added by solarissmoke 2 years ago.
Make sure we have preg-compatible EOLs
19854.2.diff (543 bytes) - added by solarissmoke 2 years ago.
The lookahead in the first patch was faulty
19854.3.diff (551 bytes) - added by solarissmoke 2 years ago.
nacin's fix

Download all attachments as: .zip

Change History (10)

comment:1 solarissmoke2 years ago

  • Keywords has-patch added

This happens with plugins also.

Tracked it down to the regex in get_file_data(). The line start/end metacharacters (^ and $) require a LF (\n) in order to detect the start/end of a line - which of course isn't there if you just have CR (\r). Fix seems relatively simple.

solarissmoke2 years ago

Make sure we have preg-compatible EOLs

comment:2 SergeyBiryukov2 years ago

  • Milestone changed from Awaiting Review to 3.4

solarissmoke2 years ago

The lookahead in the first patch was faulty

comment:3 nacin2 years ago

This probably also works:

$file_data = str_replace( array( "\r\n", "\r" ), "\n", $file_data );

comment:4 solarissmoke2 years ago

Indeed, that is much more efficient. Patch updated.

solarissmoke2 years ago

nacin's fix

comment:5 solarissmoke2 years ago

  • Summary changed from themes.php doesn't show child themes if using Mac-style CR EOL markers to themes.php doesn't show themes if using Mac-style CR EOL markers

Closed #20248 as duplicate

Last edited 2 years ago by helenyhou (previous) (diff)

comment:6 nacin2 years ago

No need to even replace \r\n; we just need to replace \r with \n. If an \r\n becomes \n\n, the function will still end up with the right data.

Added test cases in [UT703].

comment:7 nacin2 years ago

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

In [20640]:

Properly extract file headers via get_file_data() when CR line endings are used. props solarissmoke for the initial patch. fixes #19854.

Note: See TracTickets for help on using tickets.