Opened 3 months ago
Last modified 7 weeks ago
#40933 new enhancement
Improvements for get_file_data() function
| Reported by: |
|
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)
#2
@subrataemfluence
3 months ago
- Keywords has-patch added
#3
@subrataemfluence
3 months ago
Good catch! :)
#5
in reply to:
↑ 4
@subrataemfluence
3 months ago
Replying to Tkama:
Thanks a lot! :)
You are welcome:) Would you mind testing the patch and see if it works as desired?
Thank you.
Note: See
TracTickets for help on using
tickets.
The same applies to function get_plugin_data(), bacause it relies on get_file_data()