-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Harden against undefined index in _load_script_textdomain_from_src() and add types for wp_parse_url()
#11690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1206,6 +1206,7 @@ function load_script_module_textdomain( string $id, string $domain = 'default', | |
| * @return string|false The JSON-encoded translated strings on success, false otherwise. | ||
| */ | ||
| function _load_script_textdomain_from_src( string $handle, string $src, string $domain, string $path, bool $is_module ) { | ||
| /** @var WP_Textdomain_Registry $wp_textdomain_registry */ | ||
| global $wp_textdomain_registry; | ||
|
|
||
| $locale = determine_locale(); | ||
|
|
@@ -1214,7 +1215,9 @@ function _load_script_textdomain_from_src( string $handle, string $src, string $ | |
| $path = $wp_textdomain_registry->get( $domain, $locale ); | ||
| } | ||
|
|
||
| $path = untrailingslashit( $path ); | ||
| if ( $path ) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Conditional added because the |
||
| $path = untrailingslashit( $path ); | ||
| } | ||
|
|
||
| // If a path was given and the handle file exists simply return it. | ||
| $file_base = 'default' === $domain ? $locale : $domain . '-' . $locale; | ||
|
|
@@ -1231,8 +1234,17 @@ function _load_script_textdomain_from_src( string $handle, string $src, string $ | |
| $relative = false; | ||
| $languages_path = WP_LANG_DIR; | ||
|
|
||
| $src_url = wp_parse_url( $src ); | ||
| $src_url = wp_parse_url( $src ); | ||
| if ( ! $src_url ) { | ||
| return load_script_translations( false, $handle, $domain ); | ||
| } | ||
| $src_url['path'] ??= ''; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the crux for fixing the undefined index error. |
||
|
|
||
| $content_url = wp_parse_url( content_url() ); | ||
| if ( ! $content_url ) { | ||
| return load_script_translations( false, $handle, $domain ); | ||
| } | ||
|
|
||
| $plugins_url = wp_parse_url( plugins_url() ); | ||
| $site_url = wp_parse_url( site_url() ); | ||
| $theme_root = get_theme_root(); | ||
|
|
@@ -1304,7 +1316,7 @@ function _load_script_textdomain_from_src( string $handle, string $src, string $ | |
| $relative = apply_filters( 'load_script_textdomain_relative_path', $relative, $src, $is_module ); | ||
|
|
||
| // If the source is not from WP. | ||
| if ( false === $relative ) { | ||
| if ( ! is_string( $relative ) ) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since |
||
| return load_script_translations( false, $handle, $domain ); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.