Ticket #45528: 45528.4.patch
File 45528.4.patch, 3.7 KB (added by , 5 years ago) |
---|
-
src/wp-includes/l10n.php
924 924 925 925 $obj = $wp_scripts->registered[ $handle ]; 926 926 927 $src = $obj->src; 928 if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $wp_scripts->content_url && 0 === strpos( $src, $wp_scripts->content_url ) ) ) { 929 $src = $wp_scripts->base_url . $src; 930 } 927 931 /** This filter is documented in wp-includes/class.wp-scripts.php */ 928 $src = esc_url( apply_filters( 'script_loader_src', $ obj->src, $handle ) );932 $src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) ); 929 933 930 934 $relative = false; 931 935 $languages_path = WP_LANG_DIR; … … 937 941 // If the host is the same or it's a relative URL. 938 942 if ( 939 943 strpos( $src_url['path'], $content_url['path'] ) === 0 && 940 ( ! isset( $src_url['host'] ) || $src_url['host'] !== $content_url['host'] )944 ( ! isset( $src_url['host'] ) || $src_url['host'] === $content_url['host'] ) 941 945 ) { 942 946 // Make the src relative the specific plugin or theme. 943 $relative = trim( substr( $src , strlen( $content_url['path'] ) ), '/' );947 $relative = trim( substr( $src_url['path'], strlen( $content_url['path'] ) ), '/' ); 944 948 $relative = explode( '/', $relative ); 945 949 946 950 $languages_path = WP_LANG_DIR . '/' . $relative[0]; … … 947 951 948 952 $relative = array_slice( $relative, 2 ); 949 953 $relative = implode( '/', $relative ); 950 } elseif ( ! isset( $src_url['host'] ) || $src_url['host'] !== $site_url['host'] ) {954 } elseif ( ! isset( $src_url['host'] ) || $src_url['host'] === $site_url['host'] ) { 951 955 if ( ! isset( $site_url['path'] ) ) { 952 956 $relative = trim( $src_url['path'], '/' ); 953 } elseif ( ( strpos( $src_url['path'], $site_url['path']) === 0 ) ) {957 } elseif ( ( strpos( $src_url['path'], trailingslashit( $site_url['path'] ) ) === 0 ) ) { 954 958 // Make the src relative to the WP root. 955 $relative = substr( $src , strlen( $site_url['path'] ) );959 $relative = substr( $src_url['path'], strlen( $site_url['path'] ) ); 956 960 $relative = trim( $relative, '/' ); 957 961 } 962 } elseif ( isset( $src_url['host'] ) && $src_url['host'] !== $site_url['host'] && false !== strpos( $src_url['path'], '/wp-includes/' ) ) { 963 // This handles CDNs that mirror all static assets. 964 $relative = substr( $src_url['path'], 1 + strpos( $src_url['path'], '/wp-includes/' ) ); 958 965 } 959 966 960 967 // If the source is not from WP. -
tests/phpunit/tests/l10n/loadScriptTextdomain.php
1 <?php 2 3 /** 4 * @group l10n 5 * @group i18n 6 */ 7 class Tests_L10n_loadScriptTextdomain extends WP_UnitTestCase { 8 /** 9 * @ticket 45528 10 */ 11 public function test_resolve_relative_path() { 12 $json_translations = file_get_contents( DIR_TESTDATA . '/languages/en_US-813e104eb47e13dd4cc5af844c618754.json' ); 13 14 wp_enqueue_script( 'test-example-root', '/wp-includes/js/script.js', array(), null ); 15 $this->assertEquals( $json_translations, load_script_textdomain( 'test-example-root', 'default', DIR_TESTDATA . '/languages' ) ); 16 17 wp_enqueue_script( 'test-example-cdn', 'https://c0.wp.com/c/5.0.1/wp-includes/js/script.js', array(), null ); 18 $this->assertEquals( $json_translations, load_script_textdomain( 'test-example-cdn', 'default', DIR_TESTDATA . '/languages' ) ); 19 20 update_option( 'siteurl', get_option( 'siteurl' ) . 'wp/' ); 21 wp_enqueue_script( 'test-example-subdir', '/wp/wp-includes/js/script.js', array(), null ); 22 $this->assertEquals( $json_translations, load_script_textdomain( 'test-example-subdir', 'default', DIR_TESTDATA . '/languages' ) ); 23 24 } 25 }