WordPress.org

Make WordPress Core

Opened 6 years ago

Last modified 5 years ago

#34591 new defect (bug)

BugFix to WP_Scripts::do_item(), remove doubled "//" — at Version 2

Reported by: jan.mazanek Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.3.1
Component: Script Loader Keywords: reporter-feedback needs-patch needs-unit-tests
Focuses: Cc:

Description (last modified by johnbillion)

Current code in do_item() of class.wp-script.php on line 172:

$src = $this->base_url . $src;

may produce duplicate slashes "//", resulting in problems.

This might be fixed with code:

$src = $this->base_url . $src;

Currently:

  • WP_Scripts contains: "public $base_url; // Full URL with trailing slash" and
  • script-loader.php contains calls $scripts->add() with initial "/" in relative paths

Together this produces doubled slashes "//". For example:
http://www.ocelovehaly.cz/ll//wp-includes/js/jquery/jquery.js?ver=1.11.3

This makes W3TC include script in minified version, but not to remove it from the original HTML.

Including jQuery twice makes LayerSlider not to work.

Please, could you bugfix class.wp-script.php on line 172?

Thank you :-)

Change History (2)

#1 in reply to: ↑ description @jan.mazanek
6 years ago

To be able to update Wordpress, untill this fix is included, it should be more secure to solve this with filter:

function abeo_script_loader_src($src, $handle) {
	$path = parse_url($src, PHP_URL_PATH);
	if(!empty($path)) {
		$replaced = 0;
		$pathReplaced = str_replace('//', '/', $path, $replaced);
		if($replaced) {
			$src = str_replace($path, $pathReplaced, $src);
		}
	}
	return $src;
}

add_filter('script_loader_src', 'abeo_script_loader_src', 10, 2);
Last edited 6 years ago by jan.mazanek (previous) (diff)

#2 @johnbillion
6 years ago

  • Description modified (diff)
  • Keywords reporter-feedback added

Thanks for the report, @jan.mazanek.

  • Can you explain a little more about why you think this double slash is appearing?
  • What's the value of the home option in the wp_options table in your database?
  • Does the bug remain if you disable all the plugins on your site and switch to one of the default themes?
  • Is there anything unusual about the configuration of your site?
Note: See TracTickets for help on using tickets.