Opened 7 years ago
Last modified 7 years ago
#40933 new enhancement
Improvements for get_file_data() function
Reported by: | Tkama | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 4.7.5 |
Component: | Formatting | Keywords: | has-patch |
Focuses: | template | Cc: |
Description
It seams as a bug or as imperfection at least.
I try to explain in example.
Assume we have such comments in file:
<?php /* Plugin Name: My plug Version: 1.0 */ // and trying to get file data like: $data = get_file_data( __FILE__, ['ver'=>'Version'] ); echo $data['ver']; //> 1.0
This is works as we need.
BUT if we change comments a little, the get_file_data() becomes broken:
<?php /* Plugin Name : My plug Version : 1.0 */ // and trying to get file data like^ $data = get_file_data( __FILE__, ['ver'=>'Version'] ); echo $data['ver']; //> ''
All we do just add spaces before :
to make comments more readable...
-
Solution
I think it's better to improve regular expression of the get_file_data() and add [\t ]*
before :
<?php if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . ':(.*)$/mi', $file_data, $match ) && $match[1] ) to if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( $regex, '/' ) . '[\t ]*:(.*)$/mi', $file_data, $match ) && $match[1] )
Attachments (1)
Change History (7)
Note: See
TracTickets for help on using
tickets.
The same applies to function
get_plugin_data()
, bacause it relies onget_file_data()