The locale module defines a hook_url_outbound_alter that gets called when url() is called. This hook will call the function locale_language_url_rewrite_url in locale.inc when the language negotiation is based on URL (path prefix or domain).

This function sets the prefix option to the language prefix, causing url() to prefix it to the URL passed in (if it is a local URL). However, when a URL is passed in to a resource that actually exists on the server (e.g. images, js, css) this prefix also gets added leading to an incorrect URL being returned.

The error will not reveal itself very often, as most URL's pointing to images and such will not go through url(). An exception is the pathologic filter that does not know if a link it is altering is a link to a Drupal path or to an existing resource and thus always passes the link through url().

I'm not sure who's error this is: url() (i.e. common.inc), locale or pathologic ("url() is only meant for internal Drupal paths"). I filed it under locale, but while typing this, I am starting to doubt and am more thinking towards the component "base system".

Comments

fietserwin’s picture

Title: url(): language prefix should not be added to URL's pointing to existing resources » url()/locale_language_url_rewrite_url(): language prefix should not be added to URL's pointing to existing resources
Version: 7.x-dev » 8.x-dev
Issue tags: +Needs backport to D7

Anyone having a thought on this?

I will give an example to clarify what is going on:

$path = 'sites/default/files/my-image.jpg';
$path = url($path);
// $path now equals '/en/sites/default/files/my-image.jpg'

I think this is an error of the locale module, more specifically the URL language negotiation plugin. IMO it should not add a prefix to existing resources, though it should change domain in these cases.

idflood’s picture

I think you are right, the "locale_language_url_rewrite_url function should not prepend a language prefix if the url point to an existing ressource.
For reference these issues are possibly related to this:
#348421: Multilingual links with Pathologic
#1431146: Bad urls generated (maybe related to i18n and core 7.12)
#698880: path to images (load anim gif) corrupted when module locale is enabled
#1370402: Libraries not loaded when using i18n module

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

catch’s picture

Version: 8.9.x-dev » 7.x-dev
Issue summary: View changes
Issue tags: -Needs backport to D7 +Bug Smash Initiative

URL generation has completely changed in 8.x/9.x and we don't do rewriting on internal/asset paths, moving back to 7.x