Making WordPress.org

Changeset 11314


Ignore:
Timestamp:
11/05/2021 04:55:21 AM (3 years ago)
Author:
dd32
Message:

Translate: Custom Warnings: Support precision within printf strings, and add an extra safety check to prevent warning about an incorrect placeholder if it existed within the original.

Fixes #5927.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-custom-warnings/wporg-gp-custom-warnings.php

    r11198 r11314  
    281281        if ( $is_sprintf ) {
    282282            // Negative/Positive lookahead not used to allow the warning to include the context around the % sign.
    283             preg_match_all( '/(?P<context>[^\s%]*)%((\d+\$(?:\d+)?)?(?P<char>.))/i', $translation, $m );
     283            preg_match_all( '/(?P<context>[^\s%]*)%((\d+\$(?:\d+)?)?(\.\d+)?(?P<char>.))/i', $translation, $m );
    284284
    285285            foreach ( $m['char'] as $i => $char ) {
    286                 // % is included for escaped %%.
    287                 if ( false === strpos( 'bcdefgosux%l', $char ) ) {
     286                if (
     287                    // % is included for escaped %%.
     288                    false === strpos( 'bcdefgosux%l', $char ) &&
     289                    // Check the "placeholder" doesn't exist within the original, as an extra safety mechanism.
     290                    false === strpos( $original, $m[0][ $i ] )
     291                ) {
    288292                    $unexpected_tokens[] = $m[0][ $i ];
    289293                }
     
    316320            // l is included for wp_sprintf_l()'s custom %l format.
    317321            // @ is included for Swift (as used for iOS mobile app) %@ string format.
    318             return '(?<!%)%(\d+\$(?:\d+)?)?[bcdefgosuxEFGX%l@]';
     322            return '(?<!%)%(\d+\$(?:\d+)?)?(\.\d+)?[bcdefgosuxEFGX%l@]';
    319323        } );
    320324    }
Note: See TracChangeset for help on using the changeset viewer.