WordPress.org

Making WordPress.org

Changeset 10689


Ignore:
Timestamp:
02/17/2021 06:31:51 AM (11 months ago)
Author:
dd32
Message:

Translate: Allow for the trailing slash to be altered on plaintext urls.

This avoids triggering an error when http://wordpress.org is translated to https://wordpress.org/.

This will still trigger a warning on a trailing slash changing inside a HTML tag like <a href="..">.

See #5155.

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

    r10688 r10689  
    5252        }
    5353
    54         // Check to see if only the scheme was changed (https <=> http), discard if so.
     54        // Check to see if only the scheme (https <=> http) or a trailing slash was changed, discard if so.
    5555        foreach ( $missing_urls as $key => $missing_url ) {
    56             $scheme = parse_url( $missing_url, PHP_URL_SCHEME );
    57             $alternate_scheme = ( 'http' == $scheme ? 'https' : 'http' );
     56            $scheme               = parse_url( $missing_url, PHP_URL_SCHEME );
     57            $alternate_scheme     = ( 'http' == $scheme ? 'https' : 'http' );
    5858            $alternate_scheme_url = preg_replace( "@^$scheme(?=:)@", $alternate_scheme, $missing_url );
    5959
    60             if ( false !== ( $alternate_index = array_search( $alternate_scheme_url, $added_urls ) ) ) {
    61                 unset( $missing_urls[ $key ], $added_urls[ $alternate_index ] );
     60            $alt_urls = [
     61                // Scheme changes
     62                $alternate_scheme_url,
     63
     64                // Slashed/unslashed changes.
     65                ( '/' === substr( $missing_url, -1 )          ? rtrim( $missing_url, '/' )          : "{$missing_url}/" ),
     66
     67                // Scheme & Slash changes.
     68                ( '/' === substr( $alternate_scheme_url, -1 ) ? rtrim( $alternate_scheme_url, '/' ) : "{$alternate_scheme_url}/" ),
     69            ];
     70
     71            foreach ( $alt_urls as $alt_url ) {
     72                if ( false !== ( $alternate_index = array_search( $alt_url, $added_urls ) ) ) {
     73                    unset( $missing_urls[ $key ], $added_urls[ $alternate_index ] );
     74                }
    6275            }
    6376        }
Note: See TracChangeset for help on using the changeset viewer.