Make WordPress Core

Ticket #33387: 33387.3.diff

File 33387.3.diff, 1.8 KB (added by boblinthorst, 5 years ago)
  • src/wp-includes/functions.php

    diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
    index 0ba059ba8e..71a0522139 100644
    a b function get_file_data( $file, $default_headers, $context = '' ) {  
    62876287        }
    62886288
    62896289        foreach ( $all_headers as $field => $regex ) {
    6290                 if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, $match ) && $match[1] ) {
     6290                if ( preg_match( '/^(?:[ \t]*<\?php)?[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, $match ) && $match[1] ) {
    62916291                        $all_headers[ $field ] = _cleanup_header_comment( $match[1] );
    62926292                } else {
    62936293                        $all_headers[ $field ] = '';
  • new file tests/phpunit/data/formatting/php-open-tag-prefixed-file-header.php

    diff --git a/tests/phpunit/data/formatting/php-open-tag-prefixed-file-header.php b/tests/phpunit/data/formatting/php-open-tag-prefixed-file-header.php
    new file mode 100644
    index 0000000000..dc078607c3
    - +  
     1<?php // Template Name: Something ?>
  • tests/phpunit/tests/file.php

    diff --git a/tests/phpunit/tests/file.php b/tests/phpunit/tests/file.php
    index 730d72c5c1..a281028d37 100644
    a b class Tests_File extends WP_UnitTestCase {  
    6565                }
    6666        }
    6767
     68        /**
     69         * @group plugins
     70         * @group themes
     71         */
     72        function test_get_file_data_header_with_php_open_tag_prefix() {
     73                $headers  = array(
     74                        'TemplateName'  => 'Template Name',
     75                );
     76                $actual = get_file_data( DIR_TESTDATA . '/formatting/spaces-before-php-tag-file-header.php', $headers );
     77
     78                $expected = array(
     79                        'TemplateName' => 'Something',
     80                );
     81
     82                foreach ( $actual as $header => $value ) {
     83                        $this->assertSame( $expected[ $header ], $value, $header );
     84                }
     85        }
     86
    6887        function is_unique_writable_file( $path, $filename ) {
    6988                $fullpath = $path . DIRECTORY_SEPARATOR . $filename;
    7089