WordPress.org

Making WordPress.org

Changeset 5736


Ignore:
Timestamp:
08/03/2017 07:35:20 AM (3 years ago)
Author:
tellyworth
Message:

Plugin directory: prevent very short translations from interfering with shortcodes. Props @SergeyBiryukov.

Fixes #2919

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-i18n.php

    r5441 r5736  
    407407     */
    408408    public function translate_gp_original( $original, $translation, $content ) {
     409        $original = preg_quote( $original, '/' );
     410
    409411        if ( false === strpos( $content, '<' ) ) {
    410             $content = str_replace( $original, $translation, $content );
     412            // Don't use $translation, it may contain backreference-like characters.
     413            $content = preg_replace( "/\b{$original}\b/", '___TRANSLATION___', $content );
    411414        } else {
    412             $original = preg_quote( $original, '/' );
    413             $content  = preg_replace( "/(<([a-z0-9]*)\b[^>]*>){$original}(<\/\\2>)/m", '${1}___TRANSLATION___${3}', $content ); // Don't use $translation, it may contain backreference-like characters.
    414             $content  = str_replace( '___TRANSLATION___', $translation, $content );
    415         }
     415            // Don't use $translation, it may contain backreference-like characters.
     416            $content = preg_replace( "/(<([a-z0-9]*)\b[^>]*>){$original}(<\/\\2>)/m", '${1}___TRANSLATION___${3}', $content );
     417        }
     418
     419        $content = str_replace( '___TRANSLATION___', $translation, $content );
    416420
    417421        return $content;
Note: See TracChangeset for help on using the changeset viewer.